local extension = Package("aaa_steam_cyc")
extension.extensionName = "aaa_steam"

local U = require "packages/utility/utility"
local RUtil = require "packages/aaa_fenghou/utility/rfenghou_util"
local DIY = require "packages/diy_utility/diy_utility"

Fk:loadTranslationTable{
  ["aaa_steam_cyc"] = "嘭！",
}

local eden = General(extension, "steam__eden", "west", 4, 4, General.Female)

local steam__tianzhuding = fk.CreateTriggerSkill{
  name = "steam__tianzhuding",
  events = {fk.GameStart},
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local list = RUtil.rollDice(5, 4)
    local choice_num = tonumber(room:askForChoice(player, table.map(list, function(n) return tostring(n) end), self.name))
    table.removeOne(list, choice_num)
    local options, chosen = {}, {}
    for i = 1, 5 do
      table.insert(options, "steam__tianzhuding".. i)
    end
    local choice_option = room:askForChoice(player, options, self.name)
    local choice_index = tonumber(choice_option:sub(-1, -1))
    chosen[choice_index] = choice_num

    for i = 1, 5 do
      if chosen[i] == nil then
        local rand = table.remove(list, math.random(1, #list))
        chosen[i] = rand
      end
    end
    local maxHp = table.remove(chosen, 1)
    room:setPlayerMark(player, "@steam__tianzhuding", table.concat(chosen, ","))
    room:changeMaxHp(player, maxHp - player.maxHp)
  end,
}

local steam__tianzhuding_delay = fk.CreateTriggerSkill{
  name = "#steam__tianzhuding_delay",
  priority = 1.1,
  mute = true,
  events = {fk.Damaged, fk.DrawNCards},
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    if player == target and player:getMark("@steam__tianzhuding") ~= 0 then
      if event == fk.Damaged and player:getMark("steam__tianzhuding_draw-round") ~= 0 then return false end
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local split = player:getMark("@steam__tianzhuding"):split(",")
    if event == fk.DrawNCards then
      data.n = tonumber(split[1])
    else
      room:setPlayerMark(player, "steam__tianzhuding_draw-round", 1)
      player:drawCards(tonumber(split[2]), "steam__tianzhuding")
    end
  end,
}
steam__tianzhuding:addRelatedSkill(steam__tianzhuding_delay)

local steam__tianzhuding_maxcards = fk.CreateMaxCardsSkill{
  name = "#steam__tianzhuding_maxcards",
  correct_func = function(self, player)
    local mark = player:getMark("@steam__tianzhuding")
    if mark ~= 0 then
      return tonumber(mark:split(",")[4])
    end
  end,
}
steam__tianzhuding:addRelatedSkill(steam__tianzhuding_maxcards)

local steam__tianzhuding_attackrange = fk.CreateAttackRangeSkill{
  name = "#steam__tianzhuding_attackrange",
  correct_func = function (self, player, to)
    local mark = player:getMark("@steam__tianzhuding")
    if mark ~= 0 then
      return tonumber(mark:split(",")[3])
    end
  end,
}
steam__tianzhuding:addRelatedSkill(steam__tianzhuding_attackrange)

eden:addSkill(steam__tianzhuding)

Fk:loadTranslationTable{
  ["steam__eden"] = "伊甸",
  ["#steam__eden"] = "",
  ["designer:steam__eden"] = "cyc",
  ["illustrator:steam__eden"] = "",

  ["steam__tianzhuding"] = "天注定",
  [":steam__tianzhuding"] = "锁定技，游戏开始时，你抽取五个1-4之间的随机数，然后你选择其中一个值赋予以下一项，然后其余数值随机分配给剩余项：体力上限、摸牌阶段额定摸牌数、每轮首次受到伤害后的摸牌数、初始攻击范围、手牌上限加值。",
  --["#steam__tianzhuding-choice"] = "天注定：请选择1个骰子数作为你的 %arg",
  ["@steam__tianzhuding"] = "天注定",
  ["#steam__tianzhuding_delay"] = "天注定",
  ["steam__tianzhuding1"] = "体力上限",
  ["steam__tianzhuding2"] = "额定摸牌数",
  ["steam__tianzhuding3"] = "受伤摸牌数",
  ["steam__tianzhuding4"] = "攻击范围初值",
  ["steam__tianzhuding5"] = "手牌上限加值",
}

local error_eden = General(extension, "steam__error_eden", "west", 4, 4, General.Female)

local errorSkill = fk.CreateTriggerSkill{
  name = "steam__cuowuji",
  events = {fk.Damaged, fk.Damage},
  anim_type = "negative",
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self) then
      if event == fk.Damaged then
        return data.from and data.from ~= player and not player:isAllNude()
      else
        local damageEvent = player.room.logic:getActualDamageEvents(1, function(e) return e.data[1].from == player end)[1]
        return damageEvent and damageEvent.data[1] == data
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.Damaged then
      local cards = player:getCardIds("hej")
      room:recastCard(cards, player, self.name)
    else
      for _, p in ipairs(room:getAlivePlayers()) do
        if not p.dead and (p.general == "steam__error_eden" or p.deputyGeneral == "steam__error_eden") then
          p:drawCards(1, self.name)
        end
      end
      if not data.to.dead then
        room:handleAddLoseSkills(data.to, self.name)
      end
    end
  end,
}
error_eden:addSkill(errorSkill)

Fk:loadTranslationTable{
  ["steam__error_eden"] = "堕化伊甸",
  ["#steam__error_eden"] = "",
  ["designer:steam__error_eden"] = "cyc",
  ["illustrator:steam__error_eden"] = "",

  ["steam__cuowuji"] = "错误技",
  [":steam__cuowuji"] = "锁定技，你受到其他角色造成的伤害后，重铸区域内的所有牌。你每回合首次造成伤害后，“堕化伊甸”摸一张牌，然后若受伤角色没有〖错误技〗，其获得之。",
}

local eve = General(extension, "steam__eve", "west", 3, 3, General.Female)

local TabooGate = fk.CreateTriggerSkill{
  name = "steam__jinjizhimen",
  events = {fk.RoundStart},
  anim_type = "defensive",
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local cardInfo = room:getTag("steam__jinjizhimen_peachInfo")
    if cardInfo == nil then
      cardInfo = {}
      for _, card in ipairs(Fk.cards) do
        if card.name == "peach" then
          table.insert(cardInfo, {card.suit, card.number})
        end
      end
      room:setTag("steam__jinjizhimen_peachInfo", cardInfo)
    end
    cardInfo = table.random(cardInfo)
    local card = room:printCard("peach", cardInfo[1], cardInfo[2])
    room:addTableMark(player, "steam__jinjizhimen_record", card.id)
    room:setCardMark(card, "@@steam__jinjizhimen", player.id)
    room:moveCardTo(card, Card.PlayerHand, player, fk.ReasonJustMove, self.name, "", true)
  end,
}

local TabooGate_maxcards = fk.CreateMaxCardsSkill{
  name = "#steam__jinjizhimen_maxcards",
  exclude_from = function(self, player, card)
    return card and card:getMark("@@steam__jinjizhimen") == player.id and player:hasSkill(TabooGate)
  end,
}
TabooGate:addRelatedSkill(TabooGate_maxcards)

local TabooGate_draw = fk.CreateTriggerSkill{
  name = "#steam__jinjizhimen_draw",
  anim_type = "drawcard",
  main_skill = TabooGate,
  priority = 0.99,
  frequency = Skill.Compulsory,
  events = {fk.AfterCardsMove},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(TabooGate) and table.find(player:getCardIds("h"), function (id)
      return Fk:getCardById(id):getMark("@@steam__jinjizhimen") == player.id
    end) ~= nil then
      for _, move in ipairs(data) do
        if #move.moveInfo > 1 and ((move.from == player.id and move.to ~= player.id) or
          (move.to == player.id and move.toArea == Card.PlayerHand)) then
          return true
        end
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    player:drawCards(1, TabooGate.name)
  end,
}
TabooGate:addRelatedSkill(TabooGate_draw)

eve:addSkill(TabooGate)

local EternalCurse = fk.CreateTriggerSkill{
  name = "steam__yonghengzhizhou",
  anim_type = "offensive",
  frequency = Skill.Compulsory,
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and player.phase == Player.Play and target == player
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    for i = 1, 2 do
      local tos = room:askForChoosePlayers(player, table.map(room.alive_players, Util.IdMapper), 1, 1,
      "#steam__yonghengzhizhou-choose", self.name, false)
      local to = room:getPlayerById(tos[1])
      room:damage{from = player, to = to, damage = 1, skillName = self.name}
      if not to.dead then
        local cards = table.filter(table.connect(room.draw_pile, room.discard_pile), function (id)
          return Fk:getCardById(id).is_damage_card
        end)
        if #cards > 0 then
          room:moveCardTo(table.random(cards, 2), Card.PlayerHand, to, fk.ReasonJustMove, self.name, "", true)
        end
      end
      if player.dead or player:getMark("steam__yonghengzhizhou_lose") == 0 then return end
    end
  end,
  
  refresh_events = {fk.AfterCardsMove},
  can_refresh = function (self, event, target, player, data)
    if player:hasSkill(self, true) and player:getMark("steam__yonghengzhizhou_lose") == 0 then
      for _, move in ipairs(data) do
        if move.from == player.id then
          for _, info in ipairs(move.moveInfo) do
            if info.fromArea == Card.PlayerHand and Fk:getCardById(info.cardId):getMark("@@steam__jinjizhimen") == player.id then
              return true
            end
          end
        end
      end
    end
  end,
  on_refresh = function (self, event, target, player, data)
    player.room:setPlayerMark(player, "steam__yonghengzhizhou_lose", 1)
  end,
}
eve:addSkill(EternalCurse)

Fk:loadTranslationTable{
  ["steam__eve"] = "夏娃",
  ["#steam__eve"] = "",
  ["designer:steam__eve"] = "cyc",
  ["illustrator:steam__eve"] = "",

  ["steam__jinjizhimen"] = "禁忌之门",
  [":steam__jinjizhimen"] = "锁定技，每轮开始时，你获得一张不计入手牌上限的【桃】。若你持有以此法获得的【桃】，你一次性获得或失去至少两张牌后，摸一张牌。",
  ["@@steam__jinjizhimen"] = "禁忌之门",
  ["#steam__jinjizhimen_draw"] = "禁忌之门",

  ["steam__yonghengzhizhou"] = "永恒之咒",
  [":steam__yonghengzhizhou"] = "锁定技，出牌阶段开始时，你须对一名角色造成1点伤害，然后其随机获得两张伤害牌；若你失去过〖永恒之咒〗获得的【桃】，则再执行一次。",
  ["#steam__yonghengzhizhou-choose"] = "永恒之咒：你须对一名角色造成1点伤害，再令其获得两张伤害牌",
}

local corrupted_eve = General(extension, "steam__corrupted_eve", "west", 3, 3, General.Female)

local xuehcao = fk.CreateActiveSkill{
  name = "steam__xuehcao",
  anim_type = "negative",
  prompt = "#steam__xuehcao",
  card_num = 0,
  target_num = 0,
  card_filter = Util.FalseFunc,
  can_use = function(self, player)
    return player.hp > 0
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    room:loseHp(player, 1, self.name)
  end,
}
local xuehcao_trigger = fk.CreateTriggerSkill{
  name = "#steam__xuehcao_trigger",
  events = {fk.HpChanged},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(xuehcao) and data.num < 0 then
      local first = player.room.logic:getEventsOfScope(GameEvent.ChangeHp, 1, function(e)
        return e.data[1] == player and e.data[2] < 0
      end, Player.HistoryTurn)[1]
      if first then
        local current = player.room.logic:getCurrentEvent():findParent(GameEvent.ChangeHp, true)
        return current and current.id == first.id
      end
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local choice = table.random({"use", "draw"})
    for i = 0, 50 do
      local name = (i == 0 and "steam__zhiyi_" or "steam"..i.."__zhiyi_") .. choice
      if Fk.skills[name] and not player:hasSkill(name, true, true) then
        room:handleAddLoseSkills(player, name)
        break
      end
    end
  end,
}
xuehcao:addRelatedSkill(xuehcao_trigger)
corrupted_eve:addSkill(xuehcao)

local xueming = fk.CreateActiveSkill{
  name = "steam__xueming",
  anim_type = "drawcard",
  prompt = "#steam__xueming-ask",
  card_num = 0,
  target_num = 0,
  card_filter = Util.FalseFunc,
  can_use = function(self, player)
    return player.hp > 0
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local skills = table.map(table.filter(player.player_skills, function (s)
      return s:isPlayerSkill(player) and s.visible
    end), Util.NameMapper)
    if #skills == 0 then return end
    local tolose = room:askForChoice(player, skills, self.name, "#steam__xueming-lose", true)
    room:handleAddLoseSkills(player, "-"..tolose)
    if player.dead then return end
    local suit = room:askForChoice(player, {"log_heart", "log_spade"}, self.name)
    suit = suit:sub(5, -1)
    local ids = room:getCardsFromPileByRule(".|.|"..suit)
    if #ids > 0 then
      room:obtainCard(player, ids, true, fk.ReasonJustMove, player.id, self.name)
    end
  end,
}
local xueming_trigger = fk.CreateTriggerSkill{
  name = "#steam__xueming_trigger",
  anim_type = "drawcard",
  main_skill = xueming,
  events = {fk.EnterDying},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(xueming)
  end,
  on_cost = function (self, event, target, player, data)
    return player.room:askForSkillInvoke(player, xueming.name, nil, "#steam__xueming-ask")
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    xueming:onUse(room, {from = player.id, tos = {player.id}, cards = {}})
  end,
}
xueming:addRelatedSkill(xueming_trigger)
corrupted_eve:addSkill(xueming)

for loop = 0, 50, 1 do  --50个应该够用
  local zhiyi = fk.CreateTriggerSkill{
    name = loop == 0 and "steam__zhiyi_use" or "steam"..loop.."__zhiyi_use",
    mute = true,
    frequency = Skill.Compulsory,
    events = {fk.TurnEnd},
    can_trigger = function(self, event, target, player, data)
      return player:hasSkill(self) and
      (#player.room.logic:getEventsOfScope(GameEvent.UseCard, 1, function(e)
        local use = e.data[1]
        return use.from == player.id and use.card.type == Card.TypeBasic
      end, Player.HistoryTurn) > 0 or
      #player.room.logic:getEventsOfScope(GameEvent.RespondCard, 1, function(e)
        local use = e.data[1]
        return use.from == player.id and use.card.type == Card.TypeBasic
      end, Player.HistoryTurn) > 0)
    end,
    on_use = function(self, event, target, player, data)
      local room = player.room
      player:broadcastSkillInvoke("steam__zhiyi", 1)
      room:notifySkillInvoked(player, self.name, "offensive")
      local names = {}
      room.logic:getEventsOfScope(GameEvent.UseCard, 1, function(e)
        local use = e.data[1]
        if use.from == player.id and use.card.type == Card.TypeBasic then
          table.insertIfNeed(names, use.card.name)
        end
      end, Player.HistoryTurn)
      room.logic:getEventsOfScope(GameEvent.RespondCard, 1, function(e)
        local use = e.data[1]
        if use.from == player.id and use.card.type == Card.TypeBasic then
          table.insertIfNeed(names, use.card.name)
        end
      end, Player.HistoryTurn)
      U.askForUseVirtualCard(room, player, names, nil, self.name, nil, false, true, false, true)
    end,
  }
  if loop > 0 then
    Fk:addSkill(zhiyi)
  else
    corrupted_eve:addRelatedSkill(zhiyi)
  end
  Fk:loadTranslationTable{
    [zhiyi.name] = "执义",
    [":"..zhiyi.name] = "锁定技，你使用或打出过基本牌的回合结束时，你视为使用其中一张。",
  }

  local zhiyi2 = fk.CreateTriggerSkill{
    name = loop == 0 and "steam__zhiyi_draw" or "steam"..loop.."__zhiyi_draw",
    mute = true,
    frequency = Skill.Compulsory,
    events = {fk.TurnEnd},
    can_trigger = function(self, event, target, player, data)
      return player:hasSkill(self) and
      (#player.room.logic:getEventsOfScope(GameEvent.UseCard, 1, function(e)
        local use = e.data[1]
        return use.from == player.id and use.card.type == Card.TypeBasic
      end, Player.HistoryTurn) > 0 or
      #player.room.logic:getEventsOfScope(GameEvent.RespondCard, 1, function(e)
        local use = e.data[1]
        return use.from == player.id and use.card.type == Card.TypeBasic
      end, Player.HistoryTurn) > 0)
    end,
    on_use = function(self, event, target, player, data)
      local room = player.room
      player:broadcastSkillInvoke("steam__zhiyi", 2)
      room:notifySkillInvoked(player, self.name, "drawcard")
      player:drawCards(1, self.name)
    end,
  }
  if loop > 0 then
    Fk:addSkill(zhiyi2)
  else
    corrupted_eve:addRelatedSkill(zhiyi2)
  end
  Fk:loadTranslationTable{
    [zhiyi2.name] = "执义",
    [":"..zhiyi2.name] = "锁定技，你使用或打出过基本牌的回合结束时，你摸一张牌。",
  }

end

Fk:loadTranslationTable{
  ["steam__corrupted_eve"] = "堕化夏娃",
  ["#steam__corrupted_eve"] = "",
  ["designer:steam__corrupted_eve"] = "cyc",
  ["illustrator:steam__corrupted_eve"] = "",

  ["steam__xuehcao"] = "血潮",
  [":steam__xuehcao"] = "出牌阶段，你可以失去1点体力。你每回合首次扣减体力值后，你随机获得一个仅含一个选项的〖执义〗。",
  ["#steam__xuehcao"] = "血潮：你可以失去1点体力",
  ["#steam__xuehcao_trigger"] = "血潮",

  ["steam__xueming"] = "血鸣",
  [":steam__xueming"] = "出牌阶段，或有角色濒死时，你可以失去一个技能，摸一张<font color='red'>♥</font>或♠牌。",
  ["#steam__xueming-ask"] = "血鸣：你可以失去一个技能，摸一张<font color='red'>♥</font>或♠牌",
  ["#steam__xueming-lose"] = "血鸣：请失去一个技能",
  ["#steam__xueming_trigger"] = "血鸣",
}


local azazel = General(extension, "steam__azazel", "west", 4)

local angerPour = fk.CreateTriggerSkill{
  name = "steam__fenhenqingxie",
  events = {fk.EventPhaseStart},
  priority = 1.01, -- 更改阶段内容的技能理应时机更早……
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and target == player and table.contains({Player.Draw, Player.Play, Player.Discard}, player.phase)
    and player:usedSkillTimes(self.name) < (1 + player:getMark("@steam__emokuangnu"))
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    local card = Fk:cloneCard("hanqing__enemy_at_the_gates")
    card.skillName = self.name
    if player:prohibitUse(card) then return false end
    local promot = "#hanqing__enemy_at_the_gates_skill"
    if table.contains({Player.Draw, Player.Play, Player.Discard}, player.phase) then
      promot = "#steam__fenhenqingxie-invoke:::"..U.ConvertPhse(player.phase)
    end
    local maxNum = card.skill:getMaxTargetNum(player, card)
    local targets = table.filter(room:getOtherPlayers(player, false), function (p) return not player:isProhibited(p, card) end)
    if #targets == 0 or maxNum == 0 then return false end
    local tos = room:askForChoosePlayers(player, table.map(targets, Util.IdMapper), 1, maxNum, promot, self.name, true)
    if #tos > 0 then
      room:sortPlayersByAction(tos)
      self.cost_data = {tos = tos}
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local phase
    if table.contains({Player.Draw, Player.Play, Player.Discard}, player.phase) then
      phase = U.ConvertPhse(player.phase)
    else
      phase = room:askForChoice(player, {"phase_draw", "phase_play", "phase_discard"}, self.name, "#steam__fenhenqingxie-effect")
    end
    local card = Fk:cloneCard("hanqing__enemy_at_the_gates")
    card.skillName = self.name
    room:useCard{from = player.id, tos = table.map(self.cost_data.tos, function(p) return {p} end), card = card,
    unoffsetableList = table.map(room.alive_players, Util.IdMapper),
    extra_data = {steam__fenhenqingxie_phase = phase, steam__fenhenqingxie_from = player.id}}
    return true
  end,
}

local angerPourDelay = fk.CreateTriggerSkill{
  name = "#steam__fenhenqingxie_delay",
  mute = true,
  events = {fk.AfterCardsMove},
  can_trigger = function(self, event, target, player, data)
    if player.dead then return false end
    local effect_event = player.room.logic:getCurrentEvent():findParent(GameEvent.CardEffect)
    if effect_event then
      local eff = effect_event.data[1]
      if table.contains(eff.card.skillNames, angerPour.name) and eff.extra_data and eff.extra_data.steam__fenhenqingxie_phase
      and eff.extra_data.steam__fenhenqingxie_from == player.id then -- 谨防修改使用者
        for _, move in ipairs(data) do
          if move.toArea == Card.Processing and move.moveReason == fk.ReasonJustMove then
            for _, info in ipairs(move.moveInfo) do
              if table.contains(eff.extra_data.HQenemy_at_the_gates, info.cardId) then
                return true
              end
            end
          end
        end
      end
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local effect_event = room.logic:getCurrentEvent():findParent(GameEvent.CardEffect)
    if effect_event == nil then return end
    local eff = effect_event.data[1]
    local slash, nonslash = {}, {}
    for _, move in ipairs(data) do
      if move.toArea == Card.Processing and move.moveReason == fk.ReasonJustMove then
        for _, info in ipairs(move.moveInfo) do
          if table.contains(eff.extra_data.HQenemy_at_the_gates, info.cardId) then
            if Fk:getCardById(info.cardId).trueName == "slash" then
              table.insertIfNeed(slash, info.cardId)
            else
              table.insertIfNeed(nonslash, info.cardId)
            end
          end
        end
      end
    end
    room:delay(400)
    local phase = eff.extra_data.steam__fenhenqingxie_phase
    if phase == "phase_draw" then
      local get = table.filter(nonslash, function (id) return room:getCardArea(id) == Card.Processing end)
      get = U.moveCardsHoldingAreaCheck(room, get)
      if #get > 0 then
        room:obtainCard(player, get, true, fk.ReasonJustMove, player.id, angerPour.name)
      end
    elseif phase == "phase_play" then
      local to = room:getPlayerById(eff.to)
      local x = math.min(#nonslash, #to:getCardIds("he"))
      if x > 0 then
        local throw = room:askForCardsChosen(player, to, x, x, "he", angerPour.name)
        room:throwCard(throw, angerPour.name, to, player)
      end
    elseif phase == "phase_discard" then
      local x = #slash
      room:askForDiscard(player, x, x, true, angerPour.name, false)
    end
  end,
}
angerPour:addRelatedSkill(angerPourDelay)

azazel:addSkill(angerPour)

local demonFury = fk.CreateTriggerSkill{
  name = "steam__emokuangnu",
  events = {fk.RoundEnd},
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) then
      local count = 0
      return #player.room.logic:getActualDamageEvents(1, function (e)
        local damage = e.data[1]
        if damage.from == player then
          count = count + damage.damage
        end
        return count >= player.hp
      end, Player.HistoryRound) > 0
    end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local choice = room:askForChoice(player, {"loseMaxHp", "loseHp"}, self.name)
    if choice == "loseMaxHp" then
      room:changeMaxHp(player, -1)
    else
      room:loseHp(player, 1, self.name)
    end
    if player.dead then return end
    choice = room:askForChoice(player, {"#steam__emokuangnu_use", "#steam__emokuangnu_times"}, self.name)
    if choice == "#steam__emokuangnu_times" then
      room:addPlayerMark(player, "@steam__emokuangnu", 1)
    else
      angerPour:doCost(fk.EventPhaseStart, player, player, {})
    end
  end,
}
azazel:addSkill(demonFury)

Fk:loadTranslationTable{
  ["steam__azazel"] = "阿撒泻勒",
  ["#steam__azazel"] = "",
  ["designer:steam__azazel"] = "cyc",
  ["illustrator:steam__azazel"] = "",

  ["steam__fenhenqingxie"] = "忿恨倾泻",
  [":steam__fenhenqingxie"] = "每回合限一次，摸牌/出牌/弃牌阶段，你可以改为视为使用一张不可抵消的【兵临城下】并:获得亮出的非【杀】牌/弃置目标等同于其中非【杀】牌数量的牌/弃置等同于其中【杀】数量的牌。（不足全弃）",
  ["#steam__fenhenqingxie-invoke"] = "忿恨倾泻：你可跳过 %arg，视为使用【兵临城下】(请选择目标)并执行对应效果",
  ["#steam__fenhenqingxie_delay"] = "忿恨倾泻",

  ["steam__emokuangnu"] = "恶魔狂怒",
  [":steam__emokuangnu"] = "轮次结束时，若你本轮造成的伤害数不小于当前体力值，你可以失去1点体力或体力上限，立即执行一种〖忿恨倾泻〗的效果，或令〖忿恨倾泻〗的每回合发动次数+1。",
  ["@steam__emokuangnu"] = "恶魔狂怒",
  ["#steam__emokuangnu_use"] = "使用【兵临城下】",
  ["#steam__emokuangnu_times"] = "增加〖忿恨倾泻〗次数",
  ["#steam__fenhenqingxie-effect"] = "请选择【兵临城下】的额外效果",
}

local corrupted_azazel = General(extension, "steam__corrupted_azazel", "west", 5)
Fk:loadTranslationTable{
  ["steam__corrupted_azazel"] = "堕化阿撒泻勒",
  ["#steam__corrupted_azazel"] = "",
  ["designer:steam__corrupted_azazel"] = "cyc",
  ["illustrator:steam__corrupted_azazel"] = "",
}

local bloodRoar = fk.CreateTriggerSkill{
  name = "steam__xuehou",
  anim_type = "drawcard",
  events = {fk.AfterCardsMove},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) then
      for _, move in ipairs(data) do
        if move.from == player.id then
          for _, info in ipairs(move.moveInfo) do
            if info.fromArea == Player.Hand or info.fromArea == Player.Equip then
              if Fk:getCardById(info.cardId).color == Card.Red then
                return true
              end
            end
          end
        end
      end
    end
  end,
  on_trigger = function (self, event, target, player, data)
    local n = 0
    for _, move in ipairs(data) do
      if move.from == player.id then
        for _, info in ipairs(move.moveInfo) do
          if info.fromArea == Player.Hand or info.fromArea == Player.Equip then
            if Fk:getCardById(info.cardId).color == Card.Red then
              n = n + 1
            end
          end
        end
      end
    end
    self.cancel_cost = false
    for _ = 1, n, 1 do
      if not player:hasSkill(self) or self.cancel_cost then return end
      self:doCost(event, target, player, data)
    end
  end,
  on_cost = function (self, event, target, player, data)
    local targets = table.filter(player.room:getOtherPlayers(player, false), function (p) return not p:isNude() end)
    if #targets > 0 then
      local tos = player.room:askForChoosePlayers(player, table.map(targets, Util.IdMapper), 1, 1,
      "#steam__xuehou-choose", self.name, true)
      if #tos > 0 then
        self.cost_data = {tos = tos}
        return true
      end
    end
    self.cancel_cost = true
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(self.cost_data.tos[1])
    local cards = room:askForCardChosen(player, to, "he", self.name)
    to:addToPile("$steam__xuehou", cards, false, self.name)
  end,
}

local bloodRoar_delay = fk.CreateTriggerSkill{
  name = "#steam__xuehou_delay",
  mute = true,
  events = {fk.TurnEnd},
  can_trigger = function(self, event, target, player, data)
    return #player:getPile("$steam__xuehou") > 0
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    player.room:moveCardTo(player:getPile("$steam__xuehou"), Player.Hand, player, fk.ReasonPrey, "steam__xuehou")
  end,
}

bloodRoar:addRelatedSkill(bloodRoar_delay)
corrupted_azazel:addSkill(bloodRoar)

local bloodPour = fk.CreateActiveSkill{
  name = "steam__xueqing",
  anim_type = "offensive",
  card_num = 0,
  target_num = 0,
  prompt = "#steam__xueqing",
  card_filter = Util.FalseFunc,
  interaction = function(self)
    return UI.Spin { from = 1, to = 3 }
  end,
  target_filter = function(self, to_select, selected, selected_cards)
    local to = Fk:currentRoom():getPlayerById(to_select)
    return #selected == 0 and Self.id ~= to_select and not Fk:currentRoom():getPlayerById(to_select):isNude()
  end,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) < (1 + player:getMark("@steam__emobaofa"))
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local num = self.interaction.data
    player:drawCards(num, self.name)
    if player.dead or player:isKongcheng() then return end
    local cards = player:getCardIds("h")
    if #cards > num then
      cards = room:askForCard(player, num, num, false, self.name, false, nil, "#steam__xueqing-show:::"..num)
    end
    DIY.ShowCards(player, cards)
    for i = 1, num, 1 do
      if player.dead then return end
      U.askForUseVirtualCard(room, player, "fire_attack", nil, self.name,
      "#steam__xueqing-fire:::"..i..":"..num, false)
    end
    if not player:isKongcheng() then
      local x = #DIY.GetShownCards(player)
      if x > 0 then
        room:damage { from = nil, to = player, damage = x, skillName = self.name, damageType = fk.FireDamage }
      end
    end
  end,
}
corrupted_azazel:addSkill(bloodPour)

local demonBurst = fk.CreateTriggerSkill{
  name = "steam__emobaofa",
  anim_type = "offensive",
  events = {fk.Death},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and data.damage and data.damage.from == player
    and not (data.extra_data and data.extra_data.skip_reward_punish)
  end,
  on_cost = function (self, event, target, player, data)
    return player.room:askForSkillInvoke(player, self.name, nil, "#steam__emobaofa-invoke")
  end,
  on_use = function(self, event, target, player, data)
    data.extra_data = data.extra_data or {}
    data.extra_data.skip_reward_punish = true
    player.room:addPlayerMark(player, "@steam__emobaofa", 1)
  end,
}
corrupted_azazel:addSkill(demonBurst)

Fk:loadTranslationTable{
  ["steam__xuehou"] = "血吼",
  [":steam__xuehou"] = "你失去一张红色牌后，可以移出一名其他角色的一张牌，直到回合结束。",
  ["$steam__xuehou"] = "移出",
  ["#steam__xuehou-choose"] = "血吼：你可以移出一名其他角色的一张牌，直到回合结束",

  ["steam__xueqing"] = "血倾",
  [":steam__xueqing"] = "出牌阶段限一次，你可以摸至多三张牌并明置等量的手牌，然后你视为使用等量张【火攻】；均结算后，你受到等同于你明置手牌数的火焰伤害。",
  ["#steam__xueqing"] = "你可摸至多三张牌并明置等量的手牌，再视为使用等量【火攻】，最终每剩1明置牌受到1火伤",
  ["#steam__xueqing-show"] = "血倾：请明置 %arg 张手牌",
  ["#steam__xueqing-fire"] = "血倾：请选择使用【火攻】的目标（第 %arg 张，共 %arg2 张）",

  ["steam__emobaofa"] = "恶魔爆发",
  [":steam__emobaofa"] = "你杀死角色时，可以不执行奖惩，改为令〖血倾〗的发动次数+1。",
  ["@steam__emobaofa"] = "恶魔爆发",
  ["#steam__emobaofa-invoke"] = "恶魔爆发：你可以不执行奖惩，改为令〖血倾〗的发动次数+1",
}

local cain = General(extension, "steam__cain", "west", 4)
Fk:loadTranslationTable{
  ["steam__cain"] = "该隐",
  ["#steam__cain"] = "",
  ["illustrator:steam__cain"] = "",
  ["designer:steam__cain"] = "cyc",
}

local secret_passage = fk.CreateTriggerSkill{
  name = "steam__secret_passage",
  anim_type = "drawcard",
  events = {fk.EventPhaseStart},
  can_trigger = function (self, event, target, player, data)
    return player:hasSkill(self) and target.phase == Player.Play and not target.dead and
      player:usedSkillTimes(self.name, Player.HistoryRound) == 0
  end,
  on_cost = function (self, event, target, player, data)
    if player.room:askForSkillInvoke(player, self.name, nil, "#secret_passage-invoke::"..target.id) then
      self.cost_data = {tos = {target.id}}
      return true
    end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local info = {target:getCardIds("h"), room:getNCards(4, "bottom")}
    room:setPlayerMark(target, "steam__secret_passage-turn", info)
    local moves = {}
    if #info[1] > 0 then
      table.insert(moves, {
        from = target.id,
        ids = info[1],
        toArea = Card.DrawPile,
        moveReason = fk.ReasonExchange,
        skillName = self.name,
        drawPilePosition = -1,
        moveVisible = false,
        proposer = target.id,
      })
    end
    table.insert(moves, {
      ids = info[2],
      to = target.id,
      toArea = Card.PlayerHand,
      moveReason = fk.ReasonExchange,
      skillName = self.name,
      moveVisible = false,
      proposer = target.id,
      moveMark = "@@steam__secret_passage-inhand-turn",
    })
    room:moveCards(table.unpack(moves))
  end,

  refresh_events = {fk.PreCardUse},
  can_refresh = function (self, event, target, player, data)
    return target == player and data.card:getMark("@@steam__secret_passage-inhand-turn") > 0
  end,
  on_refresh = function (self, event, target, player, data)
    data.extraUse = true
  end,
}
local secret_passage_delay = fk.CreateTriggerSkill{
  name = "#steam__secret_passage_delay",
  anim_type = "drawcard",
  events = {fk.TurnEnd},
  can_trigger = function (self, event, target, player, data)
    return player:getMark("steam__secret_passage-turn") ~= 0 and not player.dead
  end,
  on_cost = Util.TrueFunc,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local info = player:getMark("steam__secret_passage-turn")
    local moves = {}
    local cards = table.filter(info[1], function (id)
      return table.contains(room.draw_pile, id)
    end)
    if #cards > 0 then
      table.insert(moves, {
        ids = cards,
        to = player.id,
        toArea = Card.PlayerHand,
        moveReason = fk.ReasonExchange,
        skillName = "steam__secret_passage",
        moveVisible = false,
        proposer = player.id,
      })
    end
    cards = table.filter(info[2], function (id)
      return table.contains(player:getCardIds("h"), id) and Fk:getCardById(id):getMark("@@steam__secret_passage-inhand-turn") > 0
    end)
    if #cards > 0 then
      table.insert(moves, {
        from = player.id,
        ids = cards,
        toArea = Card.DrawPile,
        moveReason = fk.ReasonExchange,
        skillName = "steam__secret_passage",
        drawPilePosition = -1,
        moveVisible = false,
        proposer = player.id,
      })
    end
    if #moves > 0 then
      room:moveCards(table.unpack(moves))
    end
  end,
}
local secret_passage_targetmod = fk.CreateTargetModSkill{
  name = "#steam__secret_passage_targetmod",
  bypass_times = function(self, player, skill, scope, card, to)
    return card and card:getMark("@@steam__secret_passage-inhand-turn") > 0
  end,
}
secret_passage:addRelatedSkill(secret_passage_delay)
secret_passage:addRelatedSkill(secret_passage_targetmod)
cain:addSkill(secret_passage)
Fk:loadTranslationTable{
  ["steam__secret_passage"] = "秘密通道",
  [":steam__secret_passage"] = "每轮限一次，一名角色的出牌阶段开始时，你可以令其用所有手牌替换牌堆底的四张牌（使用时无次数限制），回合结束时换回。",
  ["#secret_passage-invoke"] = "秘密通道：是否令 %dest 用所有手牌交换牌堆底四张牌，回合结束换回？",
  ["@@steam__secret_passage-inhand-turn"] = "秘密通道",
  ["#steam__secret_passage_delay"] = "秘密通道",
}

local wall_breaker = fk.CreateTriggerSkill{
  name = "steam__wall_breaker",
  anim_type = "drawcard",
  frequency = Skill.Compulsory,
  events = {fk.AfterCardsMove},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) then
      for _, move in ipairs(data) do
        if move.to == player.id and move.toArea == Player.Hand and move.moveReason == fk.ReasonDraw then
          return true
        end
      end
    end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    room:moveCardTo(room:getNCards(2, "bottom"), Card.PlayerHand, player, fk.ReasonJustMove, self.name, nil, false, player.id)
    if player.dead or player:isKongcheng() then return end
    local cards = player:getCardIds("h")
    if #cards > 2 then
      cards = room:askForCard(player, 2, 2, false, self.name, false, nil, "#steam__wall_breaker-ask")
    end
    local result = room:askForGuanxing(player, cards, nil, nil, self.name, true, {"Top", "Bottom"})
    local moves = {}
    if #result.top > 0 then
      result.top = table.reverse(result.top)
      table.insert(moves, {
        from = player.id,
        ids = result.top,
        toArea = Card.DrawPile,
        moveReason = fk.ReasonJustMove,
        skillName = self.name,
        proposer = player.id,
        moveVisible = false,
        drawPilePosition = 1,
      })
    end
    if #result.bottom > 0 then
      table.insert(moves, {
        from = player.id,
        ids = result.bottom,
        toArea = Card.DrawPile,
        moveReason = fk.ReasonJustMove,
        skillName = self.name,
        proposer = player.id,
        moveVisible = false,
        drawPilePosition = -1,
      })
    end
    room:moveCards(table.unpack(moves))
  end,
}
cain:addSkill(wall_breaker)
Fk:loadTranslationTable{
  ["steam__wall_breaker"] = "破壁之手",
  [":steam__wall_breaker"] = "锁定技，你摸牌后，获得牌堆底的两张牌，然后你须卜算两张手牌。",
  ["#steam__wall_breaker-ask"] = "破壁之手：请选择两张手牌，置于牌堆顶或牌堆底",
}

local corrupted_cain = General(extension, "steam__corrupted_cain", "west", 4)

local mustGreat = fk.CreateTriggerSkill{
  name = "steam__zhudingweida",
  events = {fk.AfterCardsMove},
  anim_type = "drawcard",
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(self) or player:usedSkillTimes(self.name) > 1 then return false end
    local ids = {}
    for _, move in ipairs(data) do
      if move.toArea == Player.Hand then
        for _, info in ipairs(move.moveInfo) do
          if table.contains(player.player_cards[Player.Hand], info.cardId) and Fk:getCardById(info.cardId).type ~= Card.TypeBasic then
            table.insertIfNeed(ids, info.cardId)
          end
        end
      end
    end
    ids = U.moveCardsHoldingAreaCheck(player.room, ids)
    if #ids > 0 then
      self.cost_data = {cards = ids}
      return true
    end
  end,
  on_trigger = function (self, event, target, player, data)
    for _, id in ipairs(self.cost_data.cards) do
      if not player:hasSkill(self) or player:usedSkillTimes(self.name) > 1 then break end
      if table.contains(player.player_cards[Player.Hand], id) and not player:prohibitDiscard(id) then
        self:doCost(event, player, player, id)
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:throwCard(data, self.name, player, player)
    room:delay(100)
    if not player.dead then
      local ids = room:getCardsFromPileByRule(".|.|.|.|.|basic", 2)
      if #ids > 0 then
        room:obtainCard(player, ids, false, fk.ReasonJustMove, player.id, self.name)
      end
    end
  end,
}
corrupted_cain:addSkill(mustGreat)

local ownMyFate = fk.CreateViewAsSkill{
  name = "steam__mingbuyoutian",
  pattern = ".|.|.|.|.|trick,equip",
  prompt = "#steam__mingbuyoutian",
  interaction = function(self)
    local all_choices = table.filter(Fk.all_card_names, function (name)
      local card = Fk:cloneCard(name)
      return not table.contains(Fk:currentRoom().disabled_packs, card.package.name) and not card.is_derived
      and card.type ~= Card.TypeBasic
    end)
    local choices = U.getViewAsCardNames(Self, self.name, all_choices)
    if #choices > 0 then
      return U.CardNameBox { choices = choices, all_choices = all_choices }
    end
  end,
  card_filter = function(self, to_select, selected)
    return #selected < 2 and not Self:prohibitDiscard(to_select)
  end,
  view_as = function(self, cards)
    if #cards ~= 2 or not self.interaction.data then return nil end
    local c = Fk:cloneCard(self.interaction.data)
    c.skillName = self.name
    c:setMark("steam__mingbuyoutian_data", cards)
    return c
  end,
  before_use = function(self, player, use)
    local room = player.room
    local cards = use.card:getMark("steam__mingbuyoutian_data")
    local suit, number = Fk:getCardById(cards[1]):getSuitString(), Fk:getCardById(cards[2]).number
    room:throwCard(cards, self.name, player, player)
    local ids = room:getCardsFromPileByRule(".|"..number.."|"..suit.."|.|"..use.card.name, 1, "allPiles")
    if #ids > 0 then
      use.card = Fk:getCardById(ids[1])
    else
      room:sendLog{type = "#steam__mingbuyoutian_FailLog", arg = use.card.name, arg2 = "log_"..suit, arg3 = tostring(number),
      toast = true}
      return ""
    end
  end,
  enabled_at_play = function(self, player)
    return #player:getCardIds("he") > 1
  end,
  enabled_at_response = function (self, player, response)
    if not response and #player:getCardIds("he") > 1 and Fk.currentResponsePattern then
      for _, name in ipairs(Fk.all_card_names) do
        local card = Fk:cloneCard(name)
        if not table.contains(Fk:currentRoom().disabled_packs, card.package.name) and not card.is_derived
          and card.type ~= Card.TypeBasic and Exppattern:Parse(Fk.currentResponsePattern):matchExp(name) then
            return true
        end
      end
    end
  end,
}
corrupted_cain:addSkill(ownMyFate)

Fk:loadTranslationTable{
  ["steam__corrupted_cain"] = "堕化该隐",
  ["#steam__corrupted_cain"] = "",
  ["designer:steam__corrupted_cain"] = "cyc",
  ["illustrator:steam__corrupted_cain"] = "",

  ["steam__zhudingweida"] = "注定伟大",
  [":steam__zhudingweida"] = "锁定技，每回合限两次，当你获得一张非基本牌后，弃置之，然后随机获得两张基本牌。",

  ["steam__mingbuyoutian"] = "命不由天",
  [":steam__mingbuyoutian"] = "当你需要使用一张非基本牌时，你可以依次弃置两张牌(第一张取花色，第二张取点数)，然后若牌堆或弃牌堆中存在该花色点数组合的所需牌，你使用之。",
  ["#steam__mingbuyoutian"] = "命不由天：选择牌名，再选择两张牌(第一张取花色，第二张取点数)，若有所需牌，你使用之",
  ["#steam__mingbuyoutian_FailLog"] = "未检索到 %arg[%arg2%arg3]",
}

local lilith = General(extension, "steam__lilith", "west", 3, 3, General.Female)
Fk:loadTranslationTable{
  ["steam__lilith"] = "莉莉丝",
  ["#steam__lilith"] = "",
  ["designer:steam__lilith"] = "cyc",
  ["illustrator:steam__lilith"] = "",
}

local hellWay = fk.CreateTriggerSkill{
  name = "steam__diyudao",
  anim_type = "drawcard",
  frequency = Skill.Compulsory,
  events = {fk.EventPhaseStart},
  can_trigger = function (self, event, target, player, data)
    return target == player and player:hasSkill(self) and player.phase == Player.Judge
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local judge = {
      who = player,
      reason = "floating_thunder",
      pattern = ".|.|spade",
    }
    room:judge(judge)
    if judge.card.suit == Card.Spade and not player.dead then
      room:damage{
        to = player,
        damage = 1,
        damageType = fk.ThunderDamage,
        skillName = self.name,
      }
    end
    if room:getCardArea(judge.card) == Card.DiscardPile and not player.dead then
      room:obtainCard(player, judge.card, true, fk.ReasonJustMove, player.id, self.name)
    end
    return true
  end,
}
lilith:addSkill(hellWay)
Fk:loadTranslationTable{
  ["steam__diyudao"] = "地狱道",
  [":steam__diyudao"] = "锁定技，判定阶段，你改为进行一次【浮雷】判定并获得判定牌。",
}

local chongshenSkills = {"steam__chongshen", "steam__chongshen_a", "steam__chongshen_b", "steam__chongshen_c"}

local demonPregnant = fk.CreateTriggerSkill{
  name = "steam__emoshoutai",
  anim_type = "masochism",
  events = {fk.Damaged},
  on_trigger = function(self, event, target, player, data)
    for i = 1, data.damage do
      if not player:hasSkill(self) then break end
      self:doCost(event, target, player, data)
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local ids = player:drawCards(2, self.name)
    ids = table.filter(ids, function (id) return table.contains(player:getCardIds("he"), id) end)
    if player.dead or #ids == 0 then return end
    local cards = room:askForDiscard(player, 1, 1, true, self.name, true, tostring(Exppattern{ id = ids }), "#steam__emoshoutai-card", true)
    if #cards == 0 then return end
    local card = Fk:getCardById(cards[1])
    room:throwCard(cards, self.name, player, player)
    if not player.dead and card.color == Card.Black and (card.trueName == "slash"
     or (card.type == Card.TypeTrick and not card.multiple_targets)) then
      local names = {}
      for _, skill in ipairs(chongshenSkills) do
        if player:hasShownSkill(skill, true) then
          local name = "jink"
          local mark = player:getMark("@"..skill)
          if mark ~= 0 then name = mark end
          if name ~= card.name then
            table.insert(names, name)
          end
        end
      end
      if #names > 0 then
        table.insert(names, "Cancel")
        local choice = room:askForChoice(player, names, self.name, "#steam__emoshoutai-choice:::"..card.name)
        if choice == "Cancel" then return end
        local skill = table.find(chongshenSkills, function (skill)
          if player:hasShownSkill(skill, true) then
            local name = "jink"
            local mark = player:getMark("@"..skill)
            if mark ~= 0 then name = mark end
            return name == choice
          end
        end)
        if skill then
          room:setPlayerMark(player, "@"..skill, card.name)
        end
      end
    end
  end,
}
lilith:addSkill(demonPregnant)
Fk:loadTranslationTable{
  ["steam__emoshoutai"] = "恶魔受胎",
  [":steam__emoshoutai"] = "当你受到1点伤害后，你摸两张牌且可以弃置其中一张牌。若弃置了黑色【杀】或黑色单目标锦囊牌，你可以用该牌牌名替换你一个〖重身〗里的牌名。",
  ["#steam__emoshoutai-card"] = "恶魔受胎：可弃置一张牌，若弃了黑色【杀】或黑色单目标锦囊牌，可用此牌名替换〖重身〗里的牌名",
  ["#steam__emoshoutai-choice"] = "恶魔受胎：你可以用【%arg】替换一个〖重身〗里的牌名",
}

local chongshen = fk.CreateViewAsSkill{
  name = "steam__chongshen",
  pattern = ".|.|.|.|.|basic,trick",
  prompt = function (self)
    local name = "jink"
    local mark = Self:getMark("@"..self.name)
    if mark ~= 0 then name = mark end
    return "#steam__chongshen-viewas:::"..name
  end,
  card_filter = function(self, to_select, selected)
    if #selected ~= 0 then return false end
    local card = Fk:getCardById(to_select)
    return card.color == Card.Red and card:getMark("@@chongshen-inhand-round") > 0
  end,
  view_as = function(self, cards)
    if #cards ~= 1 then return nil end
    local name = "jink"
    local mark = Self:getMark("@"..self.name)
    if mark ~= 0 then name = mark end
    local c = Fk:cloneCard(name)
    c.skillName = self.name
    c:addSubcard(cards[1])
    return c
  end,
  enabled_at_response = function(self, player, response)
    if not response and Fk.currentResponsePattern then
      local name = "jink"
      local mark = Self:getMark("@"..self.name)
      if mark ~= 0 then name = mark end
      return Exppattern:Parse(Fk.currentResponsePattern):matchExp(name)
    end
  end,
  enabled_at_play = function (self, player)
    local mark = player:getMark("@"..self.name)
    return mark ~= 0 and not Fk:cloneCard(mark).is_passive
  end,
  on_lose = function (self, player)
    player.room:setPlayerMark(player, "@"..self.name, 0)
  end,
}
local chongshen_record = fk.CreateTriggerSkill{
  name = "#steam__chongshen_record",

  refresh_events = {fk.AfterCardsMove},
  can_refresh = function(self, event, target, player, data)
    return player:hasSkill(chongshen, true)
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    for _, move in ipairs(data) do
      if move.to == player.id and move.toArea == Player.Hand then
        for _, info in ipairs(move.moveInfo) do
          local id = info.cardId
          if room:getCardArea(id) == Card.PlayerHand and room:getCardOwner(id) == player then
            room:setCardMark(Fk:getCardById(id), "@@chongshen-inhand-round", 1)
          end
        end
      end
    end
  end,
}
chongshen:addRelatedSkill(chongshen_record)
lilith:addSkill(chongshen)

for _, n in ipairs({"a", "b", "c"}) do
  local skill = fk.CreateViewAsSkill{
    name = "steam__chongshen_"..n,
    pattern = chongshen.pattern,
    prompt = chongshen.prompt,
    card_filter = chongshen.cardFilter,
    view_as = chongshen.viewAs,
    enabled_at_response = chongshen.enabledAtResponse,
    enabled_at_play = chongshen.enabledAtPlay,
    on_lose = chongshen.onLose,
  }
  lilith:addSkill(skill)
  Fk:loadTranslationTable{
    [skill.name] = "重身",
    [":"..skill.name] = "你可以将一张你于当前轮次内得到的红色牌当【闪】使用。",
    ["@"..skill.name] = "重身",
  }
end

Fk:loadTranslationTable{
  ["steam__chongshen"] = "重身",
  [":steam__chongshen"] = "你可以将一张你于当前轮次内得到的红色牌当【闪】使用。",
  ["@steam__chongshen"] = "重身",
  ["#steam__chongshen-viewas"] = "重身：将一张本轮获得的红色牌当做【%arg】使用",
  ["@@steam__chongshen-inhand-round"] = "重身",
}


local samson = General(extension, "steam__samson", "west", 6)
Fk:loadTranslationTable{
  ["steam__samson"] = "参孙",
  ["#steam__samson"] = "",
  ["designer:steam__samson"] = "cyc",
  ["illustrator:steam__samson"] = "",
}

local angryGrow = fk.CreateTriggerSkill{
  name = "steam__nuyizengsheng",
  events = {fk.BeforeDrawCard},
  anim_type = "drawcard",
  frequency = Skill.Compulsory,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local ids = room:getCardsFromPileByRule(".|.|spade,club", data.num)
    if #ids > 0 then
      room:obtainCard(player, ids, false, fk.ReasonJustMove, player.id, self.name)
    end
    return true
  end,
}

local angryGrowUse = fk.CreateTriggerSkill{
  name = "#steam__nuyizengsheng_use",
  events = {fk.Damage},
  mute = true,
  frequency = Skill.Compulsory,
  can_trigger = function (self, event, target, player, data)
    if target == player and player:hasSkill(angryGrow) then
      local useEvent = player.room.logic:getCurrentEvent():findParent(GameEvent.UseCard)
      if useEvent then
        local use = useEvent.data[1]
        return use.card == data.card and use.extra_data and use.extra_data.steam__nuyizengsheng
      end
    end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local useEvent = player.room.logic:getCurrentEvent():findParent(GameEvent.UseCard)
    local use = useEvent.data[1]
    use.extra_data.steam__nuyizengsheng = false
    player:drawCards(1, angryGrow.name)
  end,

  -- 客户端啥时候才能查到记录器额……
  refresh_events = {fk.CardUsing},
  can_refresh = function (self, event, target, player, data)
    return target == player and player:hasSkill(angryGrow, true)
  end,
  on_refresh = function (self, event, target, player, data)
    player.room:addPlayerMark(player, "steam__nuyizengsheng_used-turn")
    if player:getMark("steam__nuyizengsheng_used-turn") <= player:getLostHp() then
      data.extra_data = data.extra_data or {}
      data.extra_data.steam__nuyizengsheng = true
    end
  end,
}
angryGrow:addRelatedSkill(angryGrowUse)

local angryGrow_targetmod = fk.CreateTargetModSkill{
  name = "#steam__nuyizengsheng_targetmod",
  bypass_times = function(self, player, skill, scope, card, to)
    return card and player and player:hasSkill(angryGrow) and player:getMark("steam__nuyizengsheng_used-turn") < player:getLostHp()
  end,
  bypass_distances = function(self, player, skill, card, to)
    return card and player and player:hasSkill(angryGrow) and player:getMark("steam__nuyizengsheng_used-turn") < player:getLostHp()
  end,
}
angryGrow:addRelatedSkill(angryGrow_targetmod)

samson:addSkill(angryGrow)

Fk:loadTranslationTable{
  ["steam__nuyizengsheng"] = "怒意增生",
  [":steam__nuyizengsheng"] = "锁定技，你摸牌时，改为随机获得等量张黑色牌。你每回合使用的前X张牌：没有距离、次数限制，且首次造成伤害后，你摸一张牌。(X为你的已损体力值)",
  ["#steam__nuyizengsheng_use"] = "怒意增生",
}

local corrupted_samson = General:new(extension, "steam__corrupted_samson", "west", 4)
Fk:loadTranslationTable{
  ["steam__corrupted_samson"] = "堕化参孙",
  ["#steam__corrupted_samson"] = "",
  ["designer:steam__corrupted_samson"] = "cyc",
  ["illustrator:steam__corrupted_samson"] = "",
}
local bloodthirsty = fk.CreateTriggerSkill{
  name = "steam__bloodthirsty",
  anim_type = "drawcard",
  frequency = Skill.Compulsory,
  events = {fk.EventPhaseProceeding},
  can_trigger = function (self, event, target, player, data)
    return target == player and player:hasSkill(self) and player.phase == Player.Draw
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    player._phase_end = true
    local ids = room:getCardsFromPileByRule(".|.|spade,club", 3, "allPiles")
    if #ids > 0 then
      room:obtainCard(player, ids, false, fk.ReasonJustMove, player.id, self.name)
    end
  end,
}
corrupted_samson:addSkill(bloodthirsty)
Fk:loadTranslationTable{
  ["steam__bloodthirsty"] = "嗜血",
  [":steam__bloodthirsty"] = "锁定技，摸牌阶段，你改为随机获得三张黑色牌。",
}
local thirstyblood = fk.CreateTriggerSkill{
  name = "steam__thirstyblood",
  anim_type = "masochism",
  frequency = Skill.Compulsory,
  events = {fk.Damage, fk.Damaged},
  can_trigger = function (self, event, target, player, data)
    return target == player and player:hasSkill(self) and not player:isNude()
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local cards = room:askForCard(player, 1, 999, true, self.name, true, ".|.|spade,club", "#steam__thirstyblood-ask")
    if #cards > 0 then
      room:recastCard(cards, player, self.name)
    end
  end,
}
corrupted_samson:addSkill(thirstyblood)
Fk:loadTranslationTable{
  ["steam__thirstyblood"] = "血嗜",
  [":steam__thirstyblood"] = "锁定技，你造成或受到伤害后，重铸任意张黑色牌。",
  ["#steam__thirstyblood-ask"] = "血嗜：请重铸任意张黑色牌",
}
local rage = fk.CreateTriggerSkill{
  name = "steam__rage",
  anim_type = "offensive",
  frequency = Skill.Compulsory,
  events = {fk.TurnEnd},
  can_trigger = function (self, event, target, player, data)
    return player:hasSkill(self) and player:getHandcardNum() > 0 and
      table.every(player:getCardIds("h"), function (id)
        return Fk:getCardById(id).color == Card.Red
      end) and
      #player.room.logic:getEventsOfScope(GameEvent.MoveCards, 1, function(e)
        for _, move in ipairs(e.data) do
          if move.to == player.id and move.toArea == Card.PlayerHand then
            return true
          end
          if move.from == player.id then
            for _, info in ipairs(move.moveInfo) do
              if info.fromArea == Card.PlayerHand then
                return true
              end
            end
          end
        end
      end, Player.HistoryTurn) > 0
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    room:setPlayerMark(player, "steam__rage-tmp", 1)
    while not player.dead and not player:isKongcheng() do
      local yes = false
      for _, id in ipairs(player:getCardIds("h")) do
        local card = Fk:cloneCard("fire__slash")
        card.skillName = self.name
        if table.find(room:getOtherPlayers(player), function (p)
          return player:canUseTo(card, p, {bypass_times = true, bypass_times = true})
        end) then
          yes = true
          break
        end
        card = Fk:cloneCard("duel")
        if table.find(room:getOtherPlayers(player), function (p)
          return player:canUseTo(card, p, {})
        end) then
          yes = true
          break
        end
      end
      if not yes then return end
      local success, dat = room:askForUseActiveSkill(player, "steam__rage_viewas", "#steam__rage-use", false)
      if success and dat then
        room:useVirtualCard(dat.interaction, dat.cards, player, table.map(dat.targets, Util.Id2PlayerMapper), self.name, true)
      else
        room:useVirtualCard("duel", table.random(player:getCardIds("h")), player, player:getNextAlive(), self.name, true)
      end
    end
    room:setPlayerMark(player, "steam__rage-tmp", 0)
  end,
}
local rage_viewas = fk.CreateViewAsSkill{
  name = "steam__rage_viewas",
  interaction = function ()
    return U.CardNameBox { choices = {"fire__slash", "duel"} }
  end,
  card_filter = function (self, to_select, selected)
    return table.contains(Self:getCardIds("h"), to_select)
  end,
  view_as = function(self, cards)
    if #cards ~= 1 then return end
    local card = Fk:cloneCard(self.interaction.data)
    card.skillName = "steam__rage"
    card:addSubcards(cards)
    return card
  end,
}
local rage_trigger = fk.CreateTriggerSkill{
  name = "#steam__rage_trigger",
  anim_type = "masochism",
  frequency = Skill.Compulsory,
  events = {fk.Damaged},
  can_trigger = function (self, event, target, player, data)
    return target == player and player:getMark("steam__rage-tmp") > 0
  end,
  on_use = function (self, event, target, player, data)
    player:drawCards(1, "steam__rage")
  end,
}
Fk:addSkill(rage_viewas)
rage:addRelatedSkill(rage_trigger)
corrupted_samson:addSkill(rage)
Fk:loadTranslationTable{
  ["steam__rage"] = "狂暴！",
  [":steam__rage"] = "锁定技，你手牌变动过的回合结束时，若你的手牌均为红色，你依次将手牌当火【杀】或【决斗】使用，期间你受到伤害后摸一张牌。",
  ["#steam__rage-use"] = "狂暴！将手牌当火【杀】或【决斗】使用！",
  ["steam__rage_viewas"] = "狂暴！",
  ["#steam__rage_trigger"] = "狂暴！",
}

local apollyon = General:new(extension, "steam__apollyon", "west", 4)
Fk:loadTranslationTable{
  ["steam__apollyon"] = "亚玻伦",
  ["#steam__apollyon"] = "",
  ["illustrator:steam__apollyon"] = "",
  ["designer:steam__apollyon"] = "cyc",
}

local infiniteVoid = fk.CreateTriggerSkill{
  name = "steam__wujinxukong",
  anim_type = "drawcard",
  events = {fk.AfterCardsMove},
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(self) or player:usedSkillTimes(self.name) ~= 0 then return false end
    local ids = {}
    for _, move in ipairs(data) do
      if move.toArea == Player.Hand then
        for _, info in ipairs(move.moveInfo) do
          if table.contains(player.player_cards[Player.Hand], info.cardId)
          and not player:prohibitDiscard(info.cardId) then
            table.insertIfNeed(ids, info.cardId)
          end
        end
      end
    end
    --ids = U.moveCardsHoldingAreaCheck(player.room, ids)
    if #ids > 0 then
      self.cost_data = {cards = ids}
      return true
    end
  end,
  on_cost = function (self, event, target, player, data)
    local num = #self.cost_data.cards
    if player:usedSkillTimes(self.name, Player.HistoryRound) == 0 then
      num = num * 2
    end
    num = math.min(num, 5)
    if player.room:askForSkillInvoke(player, self.name, num, "#steam__wujinxukong-ask:::"..num) then
      self.cost_data.num = num
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local cards = self.cost_data.cards
    local num = self.cost_data.num
    local skills, hasTrick = {}, false
    for _, id in ipairs(cards) do
      local card = Fk:getCardById(id)---@type EquipCard
      if card.type == Card.TypeEquip then
        local equipSkills = card:getEquipSkills(player)
        if #equipSkills > 0 then
          room:addTableMarkIfNeed(player, "@$steam__wujinxukong", card.name)--仅用于提示
          for _, s in ipairs(equipSkills) do
            table.insertIfNeed(skills, s.name)
          end
        end
      elseif card.type == Card.TypeTrick then
        hasTrick = true
      end
    end
    room:throwCard(cards, self.name, player, player)
    if player.dead then return end
    room:handleAddLoseSkills(player, table.concat(skills, "|"), self.name)
    if player.dead then return end
    player:drawCards(num, self.name)
    if player.dead then return end
    if hasTrick then
      room:addPlayerMark(player, "steam__wujinxukong_delay", 1)
    end
  end,

  on_lose = function (self, player, is_death)
    player.room:setPlayerMark(player, "@$steam__wujinxukong", 0)
  end,
}
local infiniteVoidDelay = fk.CreateTriggerSkill{
  name = "#steam__wujinxukong_delay",
  anim_type = "drawcard",
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return target.phase == Player.Start and player:getMark("steam__wujinxukong_delay") ~= 0
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local num = player:getMark("steam__wujinxukong_delay")
    player.room:setPlayerMark(player, "steam__wujinxukong_delay", 0)
    player:drawCards(num, infiniteVoid.name)
  end,
}
infiniteVoid:addRelatedSkill(infiniteVoidDelay)
apollyon:addSkill(infiniteVoid)

Fk:loadTranslationTable{
  ["steam__wujinxukong"] = "无尽虚空",
  [":steam__wujinxukong"] = "每回合限一次，你获得牌后，可以弃置之并摸等量张牌（至多摸五张，若为本轮首次发动，改为摸两倍）。若含：锦囊牌，下一名角色的准备阶段，你摸一张牌；装备牌，你获得该牌的装备技能。",
  ["#steam__wujinxukong-ask"] = "无尽虚空：你可以弃置这些牌，摸 %arg 张牌并获得其中装备牌技能",
  ["@$steam__wujinxukong"] = "无尽虚空",
  ["#steam__wujinxukong_delay"] = "无尽虚空",
}

local corrupted_apollyon = General:new(extension, "steam__corrupted_apollyon", "west", 4)
Fk:loadTranslationTable{
  ["steam__corrupted_apollyon"] = "堕化亚玻伦",
  ["#steam__corrupted_apollyon"] = "",
  ["illustrator:steam__corrupted_apollyon"] = "",
  ["designer:steam__corrupted_apollyon"] = "cyc",
}

local bottomlessPit = fk.CreateViewAsSkill{
  name = "steam__wudishenkeng",
  anim_type = "drawcard",
  pattern = ".|.|.|.|.|basic,trick",
  prompt = function (self, cards)
    if #cards == 0 then return "#steam__wudishenkeng" end
    local card = Fk:getCardById(cards[1])
    -- 服了火杀了，目前逻辑是只需要重铸同真名的牌，视为使用第一张选择的牌名
    return "#steam__wudishenkeng-card:::"..card.trueName..":"..card.name
  end,
  card_filter = function(self, to_select, selected, player)
    local card = Fk:getCardById(to_select)
    if table.contains(Self.player_cards[Player.Hand], to_select) and (card:isCommonTrick() or card.type == Card.TypeBasic) then
      if #selected == 0 then
        if Fk.currentResponsePattern == nil then
          return player:canUse(card) and not Self:prohibitUse(card)
        else
          return Exppattern:Parse(Fk.currentResponsePattern):match(card)
        end
      else
        return Fk:getCardById(selected[1]).trueName == card.trueName
      end
    end
  end,
  view_as = function(self, cards)
    if #cards == 0 then return nil end
    local card = Fk:cloneCard(Fk:getCardById(cards[1]).name)
    card:setMark(self.name, cards)
    card.skillName = self.name
    return card
  end,
  before_use = function(self, player, use)
    local room = player.room
    local cards = use.card:getMark(self.name)
    if type(cards) ~= "table" then return "" end
    if #cards > 1 then
      use.extra_data = use.extra_data or {}
      use.extra_data.steam__wudishenkengName = use.card.name
    end
    room:recastCard(cards, player, self.name)
  end,
  after_use = function(self, player, use)
    if player.dead then return end
    local room = player.room
    local mark = player:getTableMark("@$steam__wudishenkeng")
    for _,name in ipairs(mark) do
      U.askForUseVirtualCard(room, player, name, nil, self.name, nil, true, true, false, true)
      if player.dead then break end
    end
    if player.dead or not use.extra_data then return end
    local newName = use.extra_data.steam__wudishenkengName
    if newName then
      if not table.find(mark, function(name) return Fk:cloneCard(name).trueName == Fk:cloneCard(newName).trueName end) then
        room:addTableMark(player, "@$steam__wudishenkeng", newName)
      end
    end
  end,
  enabled_at_play = function(self, player)
    return not player:isKongcheng() and player:usedSkillTimes(self.name) == 0
  end,
  enabled_at_response = function (self, player, response)
    return not player:isKongcheng() and player:usedSkillTimes(self.name) == 0
    and not response and Fk.currentResponsePattern
    and table.find(player:getCardIds("h"), function (id)
      local card = Fk:getCardById(id)
      return (card:isCommonTrick() or card.type == Card.TypeBasic) and
      Exppattern:Parse(Fk.currentResponsePattern):match(card)
    end)
  end,
}
corrupted_apollyon:addSkill(bottomlessPit)

Fk:loadTranslationTable{
  ["steam__wudishenkeng"] = "无底深坑",
  [":steam__wudishenkeng"] = "每回合限一次，你需要使用一张基本牌或普通锦囊牌时，可以重铸至少一张同名牌视为使用之。若不小于两张，之后你以此法使用牌后视为使用该牌。(每牌名限追加使用一次)",
  ["#steam__wudishenkeng"] = "无底深坑：重铸至少一张同名牌视为使用需要的牌",
  ["#steam__wudishenkeng-card"] = "无底深坑：重铸任意张【%arg】视为使用【%arg2】！",
  ["@$steam__wudishenkeng"] = "无底深坑",
}

local fiora = General(extension, "steam__fiora", "west", 4, 4, General.Female)
local xunzhan = fk.CreateViewAsSkill{
  name = "steam__xunzhan",
  pattern = "slash",
  anim_type = "offensive",
  prompt = "#steam__xunzhan",
  card_filter = function(self, to_select, selected)
    return #selected == 0 and Fk:getCardById(to_select).type == Card.TypeBasic
  end,
  view_as = function(self, cards)
    if #cards ~= 1 then return end
    local card = Fk:cloneCard("slash")
    card:addSubcard(cards[1])
    card.skillName = self.name
    return card
  end,
  before_use = function(self, player, use)
    local room = player.room
    for _, p in ipairs(room.alive_players) do
      room:addTableMark(p, "@steam__xunzhan-turn", use.card:getSuitString(true))
    end
  end,
}
local xunzhan_prohibit = fk.CreateProhibitSkill{
  name = "#steam__xunzhan_prohibit",
  prohibit_use = function(self, player, card)
    return card and table.contains(player:getTableMark("@steam__xunzhan-turn"), card:getSuitString(true))
  end,
}
local jueyu = fk.CreateActiveSkill{
  name = "steam__jueyu",
  anim_type = "control",
  card_num = 0,
  target_num = 1,
  prompt = "#steam__jueyu",
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  card_filter = Util.FalseFunc,
  target_filter = function(self, to_select, selected, selected_cards)
    return #selected == 0 and to_select ~= Self.id and not Fk:currentRoom():getPlayerById(to_select):isKongcheng()
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.tos[1])
    local id = room:askForCardChosen(player, target, "h", self.name)
    target:showCards(id)
    if player.dead or target.dead then return end
    room:setPlayerMark(target, "@steam__jueyu-phase", Fk:getCardById(id):getSuitString(true))
    room:addTableMark(player, "steam__jueyu-phase", target.id)
  end,
}
local jueyu_trigger = fk.CreateTriggerSkill{
  name = "#steam__jueyu_trigger",
  mute = true,
  events = {fk.Damage},
  can_trigger = function(self, event, target, player, data)
    return target == player and not player.dead and player:usedSkillTimes("steam__jueyu", Player.HistoryPhase) > 0 and
      table.contains(player:getTableMark("steam__jueyu-phase"), data.to.id)
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local cards = table.filter(data.to:getTableMark("@$steam__jueyu"), function (id)
      return Fk:getCardById(id):getSuitString(true) == data.to:getMark("@steam__jueyu-phase")
    end)
    room:setPlayerMark(data.to, "@steam__jueyu-phase", 0)
    room:removeTableMark(player, "steam__jueyu-phase", data.to.id)
    if target.dead or #cards == 0 then
      if room:askForSkillInvoke(player, "steam__jueyu", nil, "#steam__jueyu-phase") then
        player:gainAnExtraPhase(Player.Play, true)
      end
    else
      local get, choice = U.askforChooseCardsAndChoice(player, cards, {"OK"}, "steam__jueyu",
        "#steam__jueyu-prey::"..data.to.id, {"steam__jueyu_phase", "Cancel"}, 1, 1, data.to:getTableMark("@$steam__jueyu"))
      if #get > 0 then
        room:moveCardTo(get, Card.PlayerHand, player, fk.ReasonPrey, "steam__jueyu", nil, true, player.id)
      elseif choice == "steam__jueyu_phase" then
        player:gainAnExtraPhase(Player.Play, true)
      end
    end
  end,

  refresh_events = {fk.CardShown, fk.AfterCardsMove},
  can_refresh = function(self, event, target, player, data)
    if event == fk.CardShown then
      return player:hasSkill(self, true)
    else
      return player:getMark("@$steam__jueyu") ~= 0
    end
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    if event == fk.CardShown then
      local mark = target:getTableMark("@$steam__jueyu")
      for _, id in ipairs(data.cardIds) do
        if table.contains(target:getCardIds("h"), id) then
          table.insertIfNeed(mark, id)
        end
      end
      room:setPlayerMark(target, "@$steam__jueyu", mark)
    else
      local mark = player:getTableMark("@$steam__jueyu")
      for _, move in ipairs(data) do
        if move.from == player.id then
          for _, info in ipairs(move.moveInfo) do
            if info.fromArea == Card.PlayerHand and table.contains(mark, info.cardId) then
              room:removeTableMark(player, "@$steam__jueyu", info.cardId)
            end
          end
        end
      end
    end
  end,
}
xunzhan:addRelatedSkill(xunzhan_prohibit)
jueyu:addRelatedSkill(jueyu_trigger)
fiora:addSkill(xunzhan)
fiora:addSkill(jueyu)
Fk:loadTranslationTable{
  ["steam__fiora"] = "菲奥娜",
  ["#steam__fiora"] = "无双剑姬",
  ["designer:steam__fiora"] = "CYC",
  ["illustrator:steam__fiora"] = "潘诚伟",

  ["steam__xunzhan"] = "迅斩",
  [":steam__xunzhan"] = "你可以将一张基本牌当【杀】使用或打出，若如此做，本回合所有角色不能使用与之同花色的牌。",
  ["steam__jueyu"] = "决誉",
  [":steam__jueyu"] = "出牌阶段限一次，你可以展示一名其他角色的一张手牌。若如此做，本阶段你下次对其造成伤害后，可以获得其一张被展示过的"..
  "同花色牌，或于本阶段结束后获得一个额外的出牌阶段。",
  ["#steam__xunzhan"] = "迅斩：将一张基本牌当【杀】使用或打出，本回合所有角色不能使用此花色的牌",
  ["@steam__xunzhan-turn"] = "迅斩",
  ["#steam__jueyu"] = "决誉：展示一名角色一张手牌，本阶段下次对其造成伤害后可以执行选项",
  ["@steam__jueyu-phase"] = "决誉",
  ["#steam__jueyu_trigger"] = "决誉",
  ["#steam__jueyu-phase"] = "决誉：是否获得一个额外的出牌阶段？",
  ["#steam__jueyu-prey"] = "决誉：你可以获得 %dest 一张牌或获得额外出牌阶段",
  ["steam__jueyu_phase"] = "获得额外出牌阶段",
  ["@$steam__jueyu"] = "展示牌",

  ["$steam__xunzhan1"] = "他们不敢还击。",
  ["$steam__xunzhan2"] = "动作太慢！",
  ["~steam__fiora"] = " 你们看上去像体面人，我不想下手太狠。",
}

local shaco = General(extension, "steam__shaco", "west", 1)
local fear_box = fk.CreateTriggerSkill{
  name = "steam__fear_box",
  mute = true,
  events = {"fk.GeneralAppeared", fk.AfterPlayerRevived, fk.EventPhaseStart},
  can_trigger = function (self, event, target, player, data)
    if target == player and player:hasShownSkill(self) then
      if event == "fk.GeneralAppeared" then
        return true
      elseif event == fk.AfterPlayerRevived then
        return target == player and data.reason == "rest"
      elseif event == fk.EventPhaseStart then
        return target == player and player.phase == Player.Finish
      end
    end
  end,
  on_cost = function (self, event, target, player, data)
    if event == fk.EventPhaseStart then
      return player.room:askForSkillInvoke(player, self.name, nil, "#steam__fear_box-invoke")
    else
      return true
    end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    player:broadcastSkillInvoke(self.name)
    if event == "fk.GeneralAppeared" or event == fk.AfterPlayerRevived then
      room:notifySkillInvoked(player, self.name, "drawcard")
      player:drawCards(2, self.name)
      if not player.dead and not player:isNude() then
        local success, dat = room:askForUseActiveSkill(player, "steam__fear_box_viewas", "#steam__fear_box-use", true)
        if success and dat then
          local card = Fk.skills["steam__fear_box_viewas"]:viewAs(dat.cards)
          local use = {
            from = player.id,
            tos = table.map(dat.targets, function(id) return {id} end),
            card = card,
          }
          room:useCard(use)
        end
      end
    elseif event == fk.EventPhaseStart then
      room:notifySkillInvoked(player, self.name, "special")
      room:loseHp(player, 1, self.name)
      if not player.dead then
        DIY.EnterHidden(player)
      end
    end
  end,

  refresh_events = {fk.PreDamage},
  can_refresh = function (self, event, target, player, data)
    return target == player and data.card and table.contains(data.card.skillNames, self.name)
  end,
  on_refresh = function (self, event, target, player, data)
    data.damageType = fk.IceDamage
  end,
}
local fear_box_viewas = fk.CreateViewAsSkill{
  name = "steam__fear_box_viewas",
  card_filter = function(self, to_select, selected)
    return #selected == 0
  end,
  view_as = function(self, cards)
    if #cards ~= 1 then return end
    local card = Fk:cloneCard("unexpectation")
    card.skillName = "steam__fear_box"
    card:addSubcard(cards[1])
    return card
  end,
}
local deceive_magic = fk.CreateTriggerSkill{
  name = "steam__deceive_magic",
  anim_type = "defensive",
  frequency = Skill.Compulsory,
  events = {fk.AskForPeachesDone},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self) and player:usedSkillTimes(self.name) == 0 and player.hp <= 0 then
      return table.find(player.room:getOtherPlayers(player), function (p)
        return table.contains(U.GetFriends(player.room, player), p)
      end)
    end
  end,
  on_use = function(self, event, target, player, data)
    player.room:setPlayerRest(player, 1)
  end,
}
fear_box.isHiddenSkill = true
Fk:addSkill(fear_box_viewas)
shaco:addSkill(fear_box)
shaco:addSkill(deceive_magic)
Fk:loadTranslationTable{
  ["steam__shaco"] = "萨科",
  ["#steam__shaco"] = "恶魔小丑",
  ["illustrator:steam__shaco"] = "Evan Monteiro",
  ["designer:steam__shaco"] = "cyc",

  ["steam__fear_box"] = "惊吓魔盒",
  [":steam__fear_box"] = "隐匿。你登场后，或休整归来后，你摸两张牌且可以将一张牌当造成冰冻伤害的【出其不意】使用。结束阶段，"..
  "你可以失去1点体力并隐匿。",
  ["steam__deceive_magic"] = "欺诈魔术",
  [":steam__deceive_magic"] = "锁定技，你的濒死结算后，若你未被救回，且你不是所在阵营的唯一存活者，则休整至你的下回合开始。",
  ["steam__fear_box_viewas"] = "惊吓魔盒",
  ["#steam__fear_box-use"] = "惊吓魔盒：你可以将一张牌当造成冰冻伤害的【出其不意】使用",
  ["#steam__fear_box-invoke"] = "惊吓魔盒：是否失去1点体力并隐匿？",

  ["$steam__deceive_magic1"] = "这很好玩啊！",
  ["$steam__deceive_magic2"] = "神出鬼没——就是我！",
  ["$steam__fear_box1"] = "恶作剧的对象，是你哦！",
  ["$steam__fear_box2"] = "呜呼嘿嘿！",
  ["~steam__shaco"] = "额啊——",
}

local thresh = General(extension, "steam__thresh", "west", 4)
local death_sentence = fk.CreateActiveSkill{
  name = "steam__death_sentence",
  mute = true,
  card_num = 1,
  min_target_num = 0,
  prompt = "#steam__death_sentence",
  can_use = Util.TrueFunc,
  card_filter = function(self, to_select, selected, selected_targets)
    return #selected == 0 and Fk:getCardById(to_select).suit == Card.Club
  end,
  target_filter = function(self, to_select, selected, selected_cards, _, _, player)
    if #selected_cards == 1 then
      local card = Fk:cloneCard("iron_chain")
      card:addSubcard(selected_cards[1])
      card.skillName = self.name
      return player:canUse(card) and card.skill:targetFilter(to_select, selected, selected_cards, card, nil, player)
    end
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    player:broadcastSkillInvoke(self.name, math.random(2))
    if #effect.tos == 0 then
      room:notifySkillInvoked(player, self.name, "drawcard")
      room:recastCard(effect.cards, player, self.name)
    else
      room:notifySkillInvoked(player, self.name, "control")
      room:sortPlayersByAction(effect.tos)
      room:useVirtualCard("iron_chain", effect.cards, player, table.map(effect.tos, Util.Id2PlayerMapper), self.name)
    end
  end,
}
local death_sentence_trigger = fk.CreateTriggerSkill{
  name = "#steam__death_sentence_trigger",
  anim_type = "control",
  events = {fk.AfterCardsMove},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(death_sentence) then
      local dat = {}
      for _, move in ipairs(data) do
        if move.to and player.room:getPlayerById(move.to).chained and move.toArea == Card.PlayerHand then
          dat[move.to] = (dat[move.to] or 0) + #move.moveInfo
        end
      end
      local targets = {}
      for id, count in pairs(dat) do
        if count > 1 then
          table.insertIfNeed(targets, id)
        end
      end
      if #targets > 0 then
        self.cost_data = targets
        return true
      end
    end
  end,
  on_trigger = function (self, event, target, player, data)
    local room = player.room
    local targets = table.simpleClone(self.cost_data)
    for _, id in ipairs(targets) do
      if not player:hasSkill(death_sentence) then return end
      local p = room:getPlayerById(id)
      if not p.dead then
        self:doCost(event, p, player, data)
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    if player.room:askForSkillInvoke(player, "steam__death_sentence", nil, "#steam__death_sentence-invoke::"..target.id) then
      self.cost_data = {tos = {target.id}}
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:broadcastSkillInvoke("steam__death_sentence", math.random(3, 4))
    player:drawCards(1, "steam__death_sentence")
    if player.dead or target.dead or target:isNude() or (target == player and #player:getCardIds("e") == 0) then return end
    local flag = target == player and "e" or "he"
    local card = room:askForCardChosen(player, target, flag, "steam__death_sentence", "#steam__death_sentence-prey::"..target.id)
    room:moveCardTo(card, Card.PlayerHand, player, fk.ReasonPrey, "steam__death_sentence", nil, false, player.id)
    if player.dead or player:isNude() or target.dead or target == player then return end
    card = room:askForCard(player, 1, 1, true, "steam__death_sentence", false, nil, "#steam__death_sentence-give::"..target.id)
    room:moveCardTo(card, Card.PlayerHand, target, fk.ReasonGive, "steam__death_sentence", nil, false, player.id)
  end,
}
local death_from_below = fk.CreateTriggerSkill{
  name = "steam__death_from_below",
  anim_type = "control",
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and target.chained and target ~= player and target.phase == Player.Start and
      player:usedSkillTimes(self.name, Player.HistoryRound) == 0
  end,
  on_cost = function(self, event, target, player, data)
    if player.room:askForSkillInvoke(player, self.name, data, "#steam__death_from_below-invoke::"..target.id) then
      self.cost_data = {tos = {target.id}}
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:drawCards(1, self.name)
    if player.dead or target.dead or not player:canPindian(target) then return end
    local pindian = player:pindian({target}, self.name)
    if player.dead or target.dead then return end
    if pindian.results[target.id].winner == player then
      local choice = room:askForChoice(player, {"right", "left"}, self.name, "#steam__death_from_below-choice::"..target.id)
      room:setPlayerMark(target, "@!steam__"..choice.."-turn", 1)
    elseif room:askForSkillInvoke(player, self.name, nil, "#steam__death_from_below-draw::"..target.id) then
      player:setSkillUseHistory(self.name, 0, Player.HistoryRound)
      target:drawCards(2, self.name)
    end
  end
}
local function distanceTo(from, other, mode)
  mode = mode or "both"
  if other == from then return 0 end
  if from:isRemoved() or other:isRemoved() then
    return -1
  end
  local right = 0
  local temp = from
  local try_time = 10
  for _ = 0, try_time do
    if temp == other then break end
    if not temp.dead and not temp:isRemoved() then
      right = right + 1
    end
    temp = temp.next
  end
  if temp ~= other then
    print("Distance malfunction: start and end does not match.")
  end
  local left = #Fk:currentRoom().alive_players - right - #table.filter(Fk:currentRoom().alive_players, function(p)
    return p:isRemoved()
  end)
  local ret = 0
  if mode == "left" then
    ret = left
  elseif mode == "right" then
    ret = right
  else
    ret = math.min(left, right)
  end

  local status_skills = Fk:currentRoom().status_skills[DistanceSkill] or Util.DummyTable
  for _, skill in ipairs(status_skills) do
    if skill.name ~= "#steam__death_from_below_distance" then
      local fixed = skill:getFixed(from, other)
      local correct = skill:getCorrect(from, other)
      if fixed ~= nil then
        ret = fixed
        break
      end
      ret = ret + (correct or 0)
    end
  end

  if from.fixedDistance[other] then
    ret = from.fixedDistance[other]
  end

  return math.max(ret, 1)
end
local death_from_below_distance = fk.CreateDistanceSkill{
  name = "#steam__death_from_below_distance",
  fixed_func = function(self, from, to)
    if from:getMark("@!steam__right-turn") > 0 then
      return distanceTo(from, to, "right")
    elseif from:getMark("@!steam__left-turn") > 0 then
      return distanceTo(from, to, "left")
    end
  end,
}
death_sentence:addRelatedSkill(death_sentence_trigger)
death_from_below:addRelatedSkill(death_from_below_distance)
thresh:addSkill(death_sentence)
thresh:addSkill(death_from_below)
Fk:loadTranslationTable{
  ["steam__thresh"] = "锤石",
  ["#steam__thresh"] = "魂锁典狱长",
  ["illustrator:steam__thresh"] = "Victor Maury",
  ["designer:steam__thresh"] = "cyc",

  ["steam__death_sentence"] = "死亡判决",
  [":steam__death_sentence"] = "你可以将一张♣牌当【铁索连环】使用或重铸。一名横置角色一次性获得至少两张牌后，你可以摸一张牌并获得其一张牌，"..
  "再交给其一张牌。",
  ["steam__death_from_below"] = "厄运钟摆",
  [":steam__death_from_below"] = "轮次技，其他横置角色的出牌阶段开始时，你可以摸一张牌并与其拼点：若你赢，你令其本回合仅能从一个方向计算距离；"..
  "若你没赢，你可以令其摸两张牌，重置本技能。",
  ["#steam__death_sentence"] = "死亡判决：你可以将一张♣牌当【铁索连环】使用或重铸",
  ["#steam__death_sentence_trigger"] = "死亡判决",
  ["#steam__death_sentence-invoke"] = "死亡判决：是否摸一张牌并获得 %dest 一张牌，然后交给其一张牌？",
  ["#steam__death_sentence-prey"] = "死亡判决：获得 %dest 一张牌",
  ["#steam__death_sentence-give"] = "死亡判决：请交给 %dest 一张牌",
  ["#steam__death_from_below-invoke"] = "厄运钟摆：是否摸一张牌并与 %dest 拼点？",
  ["#steam__death_from_below-choice"] = "厄运钟摆：令 %dest 本回合只能从一个方向计算距离",
  ["#steam__death_from_below-draw"] = "厄运钟摆：是否令 %dest 摸两张牌，你重置此技能？",

  ["$steam__death_sentence1"] = "把他们关起来~", -- (铁索连环)
  ["$steam__death_sentence2"] = "没有人能拯救他们。", -- (铁索连环)
  ["$steam__death_sentence3"] = "没有人可以逃脱~", -- (获得牌)
  ["$steam__death_sentence4"] = "我们要怎样进行这令人愉悦的折磨呢?", -- (获得牌)
  ["$steam__death_from_below1"] = "这边儿~",
  ["$steam__death_from_below2"] = "我们走起来~",
  ["~steam__thresh"] = "我，疯了？很有可能——",
}

local ahri = General(extension, "steam__ahri", "west", 3, 3, General.Female)
local essence_theft = fk.CreateActiveSkill{
  name = "steam__essence_theft",
  anim_type = "control",
  card_num = function (self)
    return Self:usedSkillTimes(self.name, Player.HistoryTurn) + 1
  end,
  target_num = 1,
  prompt = function (self)
    local n = Self:usedSkillTimes(self.name, Player.HistoryTurn) + 1
    return "#steam__essence_theft:::"..n..":"..(n + 1)
  end,
  can_use = Util.TrueFunc,
  card_filter = function(self, to_select, selected)
    return #selected < Self:usedSkillTimes(self.name, Player.HistoryTurn) + 1 and Fk:getCardById(to_select).suit == Card.Heart
  end,
  target_filter = function(self, to_select, selected)
    return #selected == 0 and to_select ~= Self.id and not Fk:currentRoom():getPlayerById(to_select):isNude()
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.tos[1])
    local n = player:usedSkillTimes(self.name, Player.HistoryTurn) + 1
    local cards = {}
    if #target:getCardIds("he") > n then
      cards = room:askForCardsChosen(player, target, n, n, "he", self.name, "#steam__essence_theft-prey::"..target.id..":"..n)
    else
      cards = target:getCardIds("he")
    end
    room:moveCards({
      from = player.id,
      to = target.id,
      ids = effect.cards,
      toArea = Card.PlayerHand,
      moveReason = fk.ReasonExchange,
      skillName = self.name,
      proposer = player.id,
      moveVisible = false,
    },
    {
      from = target.id,
      to = player.id,
      ids = cards,
      toArea = Card.PlayerHand,
      moveReason = fk.ReasonExchange,
      skillName = self.name,
      proposer = player.id,
      moveVisible = false,
    })
  end,
}
local spirit_rush = fk.CreateTriggerSkill{
  name = "steam__spirit_rush",
  anim_type = "control",
  events = {fk.EventPhaseEnd},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and target.phase >= Player.Start and target.phase <= Player.Finish and
      not target.dead and not target:isNude() and
      #player.room.logic:getEventsOfScope(GameEvent.MoveCards, 1, function(e)
        for _, move in ipairs(e.data) do
          if move.to == player.id and move.toArea == Card.PlayerHand then
            return true
          end
          if move.from == player.id then
            for _, info in ipairs(move.moveInfo) do
              if info.fromArea == Card.PlayerHand then
                return true
              end
            end
          end
        end
      end, Player.HistoryPhase) > 0
  end,
  on_cost = function(self, event, target, player, data)
    local prompt = "#steam__spirit_rush0-invoke::"..target.id
    if player:getMark(self.name) ~= 0 then
      if player:getMark(self.name) == Card.PlayerHand then
        prompt = "#steam__spirit_rush-invoke::"..target.id..":".."$Equip"
      elseif player:getMark(self.name) == Card.PlayerEquip then
        prompt = "#steam__spirit_rush-invoke::"..target.id..":".."$Hand"
      end
    end
    if player.room:askForSkillInvoke(player, self.name, nil, prompt) then
      self.cost_data = {tos = {target.id}}
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local prompt = "#steam__spirit_rush0-ask::"..target.id
    if player:getMark(self.name) == Card.PlayerHand then
      prompt = "#steam__spirit_rush-ask::"..target.id..":".."$Equip"
    elseif player:getMark(self.name) == Card.PlayerEquip then
      prompt = "#steam__spirit_rush-ask::"..target.id..":".."$Hand"
    end
    local card = room:askForCardChosen(player, target, "he", self.name, prompt)
    local yes = player:getMark(self.name) ~= 0 and room:getCardArea(card) ~= player:getMark(self.name)
    room:setPlayerMark(player, self.name, room:getCardArea(card))
    room:recastCard(card, target, self.name)
    if yes and not player.dead then
      player:drawCards(1, self.name)
    end
  end,
}
ahri:addSkill(essence_theft)
ahri:addSkill(spirit_rush)
Fk:loadTranslationTable{
  ["steam__ahri"] = "阿狸",
  ["#steam__ahri"] = "九尾妖狐",
  ["illustrator:steam__ahri"] = "Chengwei Pan",
  ["designer:steam__ahri"] = "cyc",

  ["steam__essence_theft"] = "摄魂夺魄",
  [":steam__essence_theft"] = "出牌阶段，你可以用X张<font color='red'>♥</font>牌交换一名其他角色的X+1张牌。（X为本回合本技能发动次数）。",
  ["steam__spirit_rush"] = "灵魄突袭",
  [":steam__spirit_rush"] = "你获得或失去过手牌的阶段结束时，你可以重铸当前回合角色一张牌。若重铸牌的区域与上次不同，你摸一张牌。",
  ["#steam__essence_theft"] = "摄魂夺魄：你可以用%arg张<font color='red'>♥</font>牌交换一名其他角色的%arg2张牌",
  ["#steam__essence_theft-prey"] = "摄魂夺魄：获得 %dest 的%arg张牌",
  ["#steam__spirit_rush0-invoke"] = "灵魄突袭：是否重铸 %dest 的一张牌？",
  ["#steam__spirit_rush-invoke"] = "灵魄突袭：是否重铸 %dest 的一张牌？若为%arg，你摸一张牌",
  ["#steam__spirit_rush0-ask"] = "灵魄突袭：重铸 %dest 的一张牌",
  ["#steam__spirit_rush-ask"] = "灵魄突袭：重铸 %dest 的一张牌，若为%arg，你摸一张牌",

  ["$steam__essence_theft1"] = "你喜欢吗?",
  ["$steam__essence_theft2"] = "mua~",
  ["$steam__spirit_rush1"] = "狐步轻盈~",
  ["$steam__spirit_rush2"] = "轻捷的步伐~",
  ["$steam__spirit_rush3"] = "跑起来吧~",
  ["~steam__ahri"] = "说不定，我能再见到他……",
}

local sylas = General(extension, "steam__sylas", "west", 4)
local petricite_burst = fk.CreateActiveSkill{
  name = "steam__petricite_burst",
  card_num = 1,
  min_target_num = 0,
  max_target_num = 2,
  prompt = "#steam__petricite_burst",
  interaction = function(self)
    local all_names = U.getAllCardNames("t")
    local names = U.getViewAsCardNames(Self, self.name, all_names, nil, {"iron_chain"})
    if #names > 0 then
      return U.CardNameBox { choices = names, all_choices = all_names }
    end
  end,
  card_filter = function(self, to_select, selected)
    return #selected == 0 and Fk:getCardById(to_select, true).trueName == "iron_chain"
  end,
  target_filter = function (self, to_select, selected, selected_cards, _, _, player)
    if #selected_cards == 1 and self.interaction.data and #selected < 2 then
      local card = Fk:cloneCard(self.interaction.data)
      card.skillName = self.name
      card:addSubcards(selected_cards)
      if card.name == "collateral" or (not card.skill.target_num and not card.multiple_targets) then
        return card.skill:targetFilter(to_select, selected, {}, card, nil, player)
      else
        if Self:canUseTo(card, Fk:currentRoom():getPlayerById(to_select)) then
          if card.multiple_targets then
            return true
          else
            return #selected == 0
          end
        end
      end
    end
  end,
  feasible = function (self, selected, selected_cards)
    if #selected_cards == 1 and self.interaction.data then
      local card = Fk:cloneCard(self.interaction.data)
      card.skillName = self.name
      card:addSubcards(selected_cards)
      if card.name == "collateral" or (not card.skill.target_num and not card.multiple_targets) then
        return card.skill:feasible(selected, {}, Self, card)
      else
        return #selected > 0 and table.every(selected, function (id)
          return Self:canUseTo(card, Fk:currentRoom():getPlayerById(id))
        end)
      end
    end
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local card = Fk:cloneCard(self.interaction.data)
    card.skillName = self.name
    card:addSubcards(effect.cards)
    if self.interaction.data == "collateral" then
      room:useCard{
        from = player.id,
        tos = table.map(effect.tos, function (id) return {id} end),
        card = card,
      }
    elseif #effect.tos > 0 then
      room:sortPlayersByAction(effect.tos)
      room:useVirtualCard(self.interaction.data, effect.cards, player, table.map(effect.tos, Util.Id2PlayerMapper), self.name)
    else
      room:useCard{
        from = player.id,
        card = card,
      }
    end
  end,
}
local petricite_burst_trigger = fk.CreateTriggerSkill{
  name = "#steam__petricite_burst_trigger",
  anim_type = "offensive",
  frequency = Skill.Compulsory,
  events = {fk.CardUseFinished},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(petricite_burst) and
      not (data.card.type == Card.TypeBasic or data.card:isCommonTrick())
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local name = "iron_chain"
    if player:getMark("steam__petricite_burst-turn") ~= 0 then
      name = player:getMark("steam__petricite_burst-turn")
    end
    local card = Fk:cloneCard(name)
    card.skillName = "steam__petricite_burst"
    if player:canUse(card) then
      local use = U.askForUseVirtualCard(room, player, name, nil, "steam__petricite_burst",
        "#steam__petricite_burst-use:::"..name, true)
      if not use then
        player:drawCards(1, "steam__petricite_burst")
      end
    else
      player:drawCards(1, "steam__petricite_burst")
    end
  end,
}
local petricite_burst_filter = fk.CreateFilterSkill{
  name = "#steam__petricite_burst_filter",
  card_filter = function(self, card, player, isJudgeEvent)
    return player:hasSkill(petricite_burst) and card.trueName == "iron_chain" and table.contains(player:getCardIds("h"), card.id)
  end,
  view_as = function(self, card, player)
    return Fk:cloneCard("nullification", card.suit, card.number)
  end,
}
local hijack = fk.CreateActiveSkill{
  name = "steam__hijack",
  anim_type = "control",
  card_num = 0,
  target_num = 1,
  prompt = "#steam__hijack",
  can_use = function(self, player)
    return player:getMark("@@rfenghou_readying:::"..self.name) == 0
  end,
  card_filter = Util.FalseFunc,
  target_filter = function(self, to_select, selected, selected_cards)
    return #selected == 0 and to_select ~= Self.id and not Fk:currentRoom():getPlayerById(to_select):isKongcheng()
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.tos[1])
    local cards1 = room:askForCardsChosen(player, target, 1, 3, "h", self.name, "#steam__hijack-show::"..target.id)
    target:showCards(cards1)
    local cards2 = {}
    if #cards1 < 3 then
      cards2 = room:getNCards(3 - #cards1)
      room:moveCardTo(cards2, Card.Processing, nil, fk.ReasonJustMove, self.name, nil, true, player.id)
    end
    local all_cards = table.simpleClone(cards1)
    table.insertTable(all_cards, table.simpleClone(cards2))
    local choices = table.filter(all_cards, function (id)
      local card = Fk:getCardById(id)
      return card.type == Card.TypeBasic or card:isCommonTrick()
    end)
    if #choices > 0 then
      local ids = U.askforChooseCardsAndChoice(player, choices, {"OK"}, self.name, "#steam__hijack-choice", nil, 1, 1, all_cards)
      room:setPlayerMark(player, "steam__petricite_burst-turn", Fk:getCardById(ids[1]).name)
      table.removeOne(all_cards, ids[1])
    end
    room:moveCardTo(all_cards, Card.PlayerHand, player, fk.ReasonPrey, self.name, nil, true, player.id)
  end,
}
hijack.RfenghouReadySkill = true
petricite_burst:addRelatedSkill(petricite_burst_trigger)
petricite_burst:addRelatedSkill(petricite_burst_filter)
sylas:addSkill(petricite_burst)
sylas:addSkill(hijack)
Fk:loadTranslationTable{
  ["steam__sylas"] = "塞拉斯",
  ["#steam__sylas"] = "解脱者",
  ["illustrator:steam__sylas"] = "Victor Maury",
  ["designer:steam__sylas"] = "cyc",

  ["steam__petricite_burst"] = "破敌禁法",
  [":steam__petricite_burst"] = "锁定技，你的实体【铁索连环】仅能视为任意其他普通锦囊牌（最多指定两名目标）。你使用一张非即时牌后，视为使用一张"..
  "【铁索连环】或摸一张牌。",
  ["steam__hijack"] = "其人之道",
  [":steam__hijack"] = "<a href='rfenghou_ready_skill'>蓄势技</a>，出牌阶段，你可以展示牌堆顶与一名其他角色手牌中共计三张牌。"..
  "你选择其中一张即时牌，令本回合〖破敌禁法〗视为使用的牌名改为该牌牌名，然后你获得其余的展示牌。",
  ["#steam__petricite_burst"] = "破敌禁法：将【铁索连环】改为其他普通锦囊牌使用（最多指定两名目标）",
  ["#steam__petricite_burst_trigger"] = "破敌禁法",
  ["#steam__petricite_burst-use"] = "破敌禁法：视为使用【%arg】，或点“取消”摸一张牌",
  ["#steam__petricite_burst_filter"] = "破敌禁法",
  ["@@rfenghou_readying:::steam__hijack"] = "其人之道 蓄势中",
  ["#steam__hijack"] = "其人之道：展示牌堆顶与一名角色手牌共计三张牌，选择其中一张为“破敌禁法”本回合视为牌名，获得其余牌",
  ["#steam__hijack-show"] = "其人之道：展示 %dest 至多三张手牌",
  ["#steam__hijack-choice"] = "其人之道：选择其中一张为“破敌禁法”本回合视为牌名，获得其余牌",

  ["$steam__petricite_burst1"] = "每一环铁链，都在为反抗添砖加瓦！",
  ["$steam__petricite_burst2"] = "阴沟和地牢，再也不会有了！",
  ["$steam__petricite_burst3"] = "欲有建设，必先破坏！",
  ["$steam__hijack1"] = "会还给你的，我保证——",
  ["$steam__hijack2"] = "交出来吧！",
  ["$steam__hijack3"] = "你的就是我的！",
  ["~steam__sylas"] = "终于，不再有墙了…",
}

local janna = General(extension, "steam__janna", "west", 3, 3, General.Female)
local tailwind = fk.CreateTriggerSkill{
  name = "steam__tailwind",
  anim_type = "support",
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and target.phase == Player.Play and not target:isNude() and not target.dead
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    if target == player then
      if room:askForSkillInvoke(player, self.name, nil, "#steam__tailwind-self") then
        self.cost_data = nil
        return true
      end
    else
      local card = room:askForCard(target, 1, 1, true, self.name, true, nil, "#steam__tailwind-invoke:"..player.id)
      if #card > 0 then
        self.cost_data = {tos = {player.id}, cards = card}
        return true
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if target ~= player then
      room:moveCardTo(self.cost_data.cards, Card.PlayerHand, player, fk.ReasonGive, self.name, nil, false, target.id)
    end
    local judge = {
      who = target,
      reason = self.name,
      pattern = ".",
    }
    room:judge(judge)
    if target.dead then return end
    room:addTableMarkIfNeed(target, "@steam__tailwind-turn", judge.card:getColorString())
    if not player.dead and not player:isNude() then
      local pattern
      if judge.card.color == Card.Red then
        pattern = ".|.|heart,diamond"
      elseif judge.card.color == Card.Black then
        pattern = ".|.|spade,club"
      else
        return
      end
      local card = room:askForCard(player, 1, 1, true, self.name, true, pattern,
        "#steam__tailwind-give::"..target.id..":"..judge.card:getColorString())
      if #card > 0 then
        if target ~= player then
          room:moveCardTo(card, Card.PlayerHand, target, fk.ReasonGive, self.name, nil, false, player.id)
        end
        if not player.dead then
          player:drawCards(1, self.name)
        end
      end
    end
  end,
}
local tailwind_targetmod = fk.CreateTargetModSkill{
  name = "#steam__tailwind_targetmod",
  bypass_distances =  function(self, player, skill, card)
    return card and table.contains(player:getTableMark("@steam__tailwind-turn"), card:getColorString())
  end,
}
local eye_of_storm = fk.CreateTriggerSkill{
  name = "steam__eye_of_storm",
  anim_type = "support",
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player.phase == Player.Discard and not player:isNude() and
      #player.room:getOtherPlayers(player) > 0 and
      not table.find(player.room.alive_players, function (p)
        return p:getMark(self.name) ~= 0
      end)
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local success, dat = room:askForUseActiveSkill(player, "steam__eye_of_storm_active", "#steam__eye_of_storm-invoke", true)
    if success and dat then
      self.cost_data = {tos = dat.targets, cards = dat.cards, choice = dat.interaction}
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(self.cost_data.tos[1])
    room:setPlayerMark(to, self.name, self.cost_data.choice)
    player:addToPile("$steam__eye_of_storm", self.cost_data.cards, false, self.name, player.id)
  end,

  refresh_events = {fk.Death},
  can_refresh = function (self, event, target, player, data)
    return target == player and (player:getMark(self.name) ~= 0 or #player:getPile("$steam__eye_of_storm") > 0)
  end,
  on_refresh = function (self, event, target, player, data)
    local room = player.room
    for _, p in ipairs(room:getAlivePlayers()) do
      room:setPlayerMark(p, self.name, 0)
      room:moveCardTo(p:getPile("$steam__eye_of_storm"), Card.DiscardPile, nil, fk.ReasonPutIntoDiscardPile)
    end
  end,
}
local eye_of_storm_trigger = fk.CreateTriggerSkill{
  name = "#steam__eye_of_storm_trigger",
  anim_type = "support",
  events = {fk.TurnEnd},
  can_trigger = function(self, event, target, player, data)
    return player:getMark("steam__eye_of_storm") ~= 0 and
      table.find(player.room.alive_players, function (p)
        return #p:getPile("$steam__eye_of_storm") > 0
      end)
  end,
  on_cost = Util.TrueFunc,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local p = table.find(room.alive_players, function (p)
      return #p:getPile("$steam__eye_of_storm") > 0
    end)
    if not table.find(room.players, function (q)
      return q:usedSkillTimes("steam__eye_of_storm", Player.HistoryTurn) > 0
    end) then
      p:addToPile("$steam__eye_of_storm", room:getNCards(1), false, "steam__eye_of_storm", player.id)
      if #p:getPile("$steam__eye_of_storm") == 0 then return end
    end
    local to = player:getMark("steam__eye_of_storm") == "right" and p:getNextAlive(true) or p:getLastAlive(true)
    if to == player then
      room:setPlayerMark(player, "steam__eye_of_storm", 0)
      room:moveCardTo(p:getPile("$steam__eye_of_storm"), Card.PlayerHand, player, fk.ReasonJustMove,
        "steam__eye_of_storm", nil, false, player.id)
    else
      to:addToPile("$steam__eye_of_storm", p:getPile("$steam__eye_of_storm"), false, "steam__eye_of_storm", player.id)
    end
  end,
}
local eye_of_storm_active = fk.CreateActiveSkill{
  name = "steam__eye_of_storm_active",
  min_card_num = 1,
  max_card_num = 3,
  target_num = 1,
  interaction = UI.ComboBox { choices = {"right", "left"} },
  card_filter = function (self, to_select, selected)
    return #selected < 3
  end,
  target_filter = function (self, to_select, selected)
    return #selected == 0 and to_select ~= Self.id
  end,
}
tailwind:addRelatedSkill(tailwind_targetmod)
Fk:addSkill(eye_of_storm_active)
eye_of_storm:addRelatedSkill(eye_of_storm_trigger)
janna:addSkill(tailwind)
janna:addSkill(eye_of_storm)
Fk:loadTranslationTable{
  ["steam__janna"] = "迦娜",
  ["#steam__janna"] = "风暴之怒",
  ["illustrator:steam__janna"] = "Jason Chan",
  ["designer:steam__janna"] = "cyc",

  ["steam__tailwind"] = "顺风而行",
  [":steam__tailwind"] = "一名角色的出牌阶段开始时，其可以交给你一张牌并判定（若为你跳过交给流程）：其本回合使用与结果同色的牌无距离限制，"..
  "然后你可以交给其一张与结果同色的牌并摸一张牌。",
  ["steam__eye_of_storm"] = "风暴之眼",
  [":steam__eye_of_storm"] = "弃牌阶段开始时，你可以移出至多三张牌，选择一名其他角色，再选择一个方向。每回合结束时，移出的牌按所选方向向"..
  "该角色移动一个座次（若当前回合角色未发动〖顺风而行〗，将牌堆顶的一张牌加入移出牌中），抵达该角色后，其获得这些牌。",
  ["#steam__tailwind-self"] = "顺风而行：是否进行判定？",
  ["#steam__tailwind-invoke"] = "顺风而行：是否交给 %src 一张牌并进行判定？你本回合使用判定颜色牌无距离限制",
  ["#steam__tailwind-give"] = "顺风而行：是否交给 %dest 一张%arg牌并摸一张牌？",
  ["@steam__tailwind-turn"] = "顺风而行",
  ["steam__eye_of_storm_active"] = "风暴之眼",
  ["#steam__eye_of_storm-invoke"] = "风暴之眼：选择目标角色和方向，将至多三张牌移出游戏，当这些牌抵达其后其获得这些牌",
  ["$steam__eye_of_storm"] = "风暴之眼",
  ["#steam__eye_of_storm_trigger"] = "风暴之眼",

  ["$steam__tailwind1"] = "如你所愿。",
  ["$steam__tailwind2"] = "风啊，带我一程吧。",
  ["$steam__eye_of_storm1"] = "风暴就要来临了——",
  ["$steam__eye_of_storm2"] = "你还以为他只是一阵无害的微风吗？",
  ["~steam__janna"] = "真理之意，与我同在……",
}

local nocturne = General(extension, "steam__nocturne", "west", 4)
local getShade = function (room, n)
  local ids = {}
  local name
  if Fk.all_card_types["shade"] then
    name = "shade"
  elseif Fk.all_card_types["rfenghou__shade"] then
    name = "rfenghou__shade"
  end
  assert(name, "服务器未加入【影】！请联系管理员安装“江山如故”或“封侯”包")
  for _, id in ipairs(room.void) do
    if n <= 0 then break end
    if Fk:getCardById(id).name == name then
      room:setCardMark(Fk:getCardById(id), MarkEnum.DestructIntoDiscard, 1)
      table.insert(ids, id)
      n = n - 1
    end
  end
  while n > 0 do
    local card = room:printCard(name, Card.Spade, 1)
    room:setCardMark(card, MarkEnum.DestructIntoDiscard, 1)
    table.insert(ids, card.id)
    n = n - 1
  end
  return ids
end
local shadow_assault = fk.CreateTriggerSkill{
  name = "steam__shadow_assault",
  anim_type = "control",
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player.phase == Player.Start
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local to = room:askForChoosePlayers(player, table.map(room.alive_players, Util.IdMapper), 1, 1,
      "#steam__shadow_assault-choose", self.name, true)
    if #to > 0 then
      self.cost_data = {tos = to}
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(self.cost_data.tos[1])
    room:setPlayerMark(player, self.name, to.id)
    room:moveCardTo(getShade(room, 3), Card.PlayerHand, to, fk.ReasonJustMove, self.name, nil, true, player.id)
  end,

  refresh_events = {fk.TurnStart},
  can_refresh = function (self, event, target, player, data)
    return target == player
  end,
  on_refresh = function (self, event, target, player, data)
    player.room:setPlayerMark(player, self.name, 0)
  end,
}
local shadow_assault_delay = fk.CreateTriggerSkill{
  name = "#steam__shadow_assault_delay",
  anim_type = "negative",
  events = {fk.CardUsing},
  can_trigger = function(self, event, target, player, data)
    return player:getMark("steam__shadow_assault") == target.id and
      table.find(target:getCardIds("h"), function (id)
        return Fk:getCardById(id).trueName == "shade"
      end)
  end,
  on_cost = Util.TrueFunc,
  on_use = function (self, event, target, player, data)
    local room = player.room
    room:doIndicate(player.id, {target.id})
    local card = table.filter(target:getCardIds("h"), function (id)
      return not target:prohibitDiscard(id)
    end)
    if #card == 0 then return end
    card = table.random(card)
    local yes = Fk:getCardById(card).trueName == "shade"
    room:throwCard(card, "steam__shadow_assault", target, target)
    if yes then
      data.tos = {}
    elseif not target.dead then
      card = table.filter(target:getCardIds("h"), function (id)
        return Fk:getCardById(id).trueName == "shade" and not target:prohibitDiscard(id)
      end)
      if #card > 0 then
        room:throwCard(card, "steam__shadow_assault", target, target)
        if not player.dead then
          player:drawCards(#card, "steam__shadow_assault")
        end
      end
    end
  end,
}
shadow_assault:addRelatedSkill(shadow_assault_delay)
nocturne:addSkill(shadow_assault)
Fk:loadTranslationTable{
  ["steam__nocturne"] = "魔腾",
  ["#steam__nocturne"] = "永恒梦魇",
  ["illustrator:steam__nocturne"] = "Francis Tneh",
  ["designer:steam__nocturne"] = "cyc",

  ["steam__shadow_assault"] = "鬼影重重",
  [":steam__shadow_assault"] = "准备阶段，你可以令一名角色获得三张【影】，直到你下回合开始，当其使用一张牌时，若其拥有【影】，"..
  "其随机弃置一张手牌：若为【影】，你令其使用的牌作废；否则，其弃置所有【影】，你摸等量的牌。",
  ["#steam__shadow_assault-choose"] = "鬼影重重：令一名角色获得三张【影】，其使用牌时随机弃置一张手牌",
  ["#steam__shadow_assault_delay"] = "鬼影重重",

  ["$steam__shadow_assault1"] = "拥抱黑暗吧！",
  ["$steam__shadow_assault2"] = "揭开帷幕！",
  ["~steam__nocturne"] = "哎呀，哎呀，哎吼，吼！",
}

local lillia = General(extension, "steam__lillia", "west", 3, 3, General.Female)
Fk:loadTranslationTable{
  ["steam__lillia"] = "莉莉娅",
  ["#steam__lillia"] = "含羞蓓蕾",
  ["illustrator:steam__lillia"] = "",
  ["designer:steam__lillia"] = "cyc",
  ["~steam__lillia"] = "哦！嚯…哦……",
}
local realIndulgenceSkill = Fk.all_card_types["indulgence"].skill
local indulgenceSkill = fk.CreateActiveSkill{
  name = "mengmanzhi__indulgence_skill",
  mod_target_filter = realIndulgenceSkill.modTargetFilter,
  target_filter = realIndulgenceSkill.targetFilter,
  target_num = 1,
  on_effect = function(self, room, effect)
    local player = room:getPlayerById(effect.to)
    local judge = {
      who = player,
      reason = "indulgence",
      pattern = ".",
    }
    room:judge(judge)
    local result = judge.card
    if result.suit == Card.Heart then
      room:recover { num = 1, skillName = self.name, who = player, recoverBy = player }
    else
      room:setPlayerMark(player, "@@steam__mengmanzhi-turn", 1)
    end
    self:onNullified(room, effect)
  end,
  on_nullified = realIndulgenceSkill.onNullified,
}
Fk:addSkill(indulgenceSkill)
local steam__mengmanzhi = fk.CreateTriggerSkill{
  name = "steam__mengmanzhi",
  events = {fk.CardEffecting},
  frequency = Skill.Compulsory,
  anim_type = "defensive",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and target == player and data.card.trueName == "indulgence"
  end,
  on_use = function(self, event, target, player, data)
    local card = data.card:clone()
    local c = table.simpleClone(data.card)
    for k, v in pairs(c) do
      card[k] = v
    end
    card.skill = indulgenceSkill
    data.card = card
  end,

  refresh_events = {fk.EventPhaseEnd},
  can_refresh = function (self, event, target, player, data)
    return target == player and player.phase == Player.Play and player:getMark("@@steam__mengmanzhi-turn") ~= 0
  end,
  on_refresh = function (self, event, target, player, data)
    player.room:setPlayerMark(player, "@@steam__mengmanzhi-turn", 0)
    player:gainAnExtraPhase(Player.Play, true)
  end,
}
lillia:addSkill(steam__mengmanzhi)

Fk:loadTranslationTable{
  ["steam__mengmanzhi"] = "梦满枝",
  [":steam__mengmanzhi"] = "锁定技，【乐不思蜀】对你的判定效果改为：若结果为<font color='red'>♥</font>，你回复1点体力；不为<font color='red'>♥</font>，本回合首个出牌阶段结束后，你再执行一个出牌阶段。",
  ["mengmanzhi__indulgence_skill"] = "乐不思蜀",
  ["@@steam__mengmanzhi-turn"] = "梦满枝",
  ["$steam__mengmanzhi1"] = "梦呀，我喜欢和你说话。",
  ["$steam__mengmanzhi2"] = "只有闭上眼睛，才能真正的看见，哈呀——",
}

local steam__feihuata = fk.CreateTriggerSkill{
  name = "steam__feihuata",
  events = {fk.RoundStart},
  anim_type = "drawcard",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and not player:isNude()
    and not player:hasDelayedTrick("indulgence") and not table.contains(player.sealedSlots, "JudgeSlot")
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    local ids = table.filter(player:getCardIds("he"), function (id)
      if Fk:getCardById(id).color == Card.Red then
        local card = Fk:cloneCard("indulgence")
        card:addSubcard(id)
        card.skillName = self.name
        return not player:prohibitUse(card) and not player:isProhibited(player, card)
      end
    end)
    local cards = room:askForCard(player, 1, 1, true, self.name, true, tostring(Exppattern{ id = ids }), "#steam__feihuata-card")
    if #cards > 0 then
      self.cost_data = {cards = cards}
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local card = Fk:cloneCard("indulgence")
    card:addSubcard(self.cost_data.cards[1])
    card.skillName = self.name
    room:useCard{from = player.id, tos = {{player.id}}, card = card}
    if not player.dead then
      player:drawCards(1, self.name)
    end
  end,
}
lillia:addSkill(steam__feihuata)

Fk:loadTranslationTable{
  ["steam__feihuata"] = "飞花挞",
  [":steam__feihuata"] = "轮次开始时，你可以将一张红色牌当【乐不思蜀】对自己使用，然后摸一张牌。",
  ["#steam__feihuata-card"] = "飞花挞：你可以将一张红色牌当【乐不思蜀】对自己使用，再摸一张牌",
  ["$steam__feihuata1"] = "梦呀，真高兴你和我在一起。",
  ["$steam__feihuata2"] = "梦呀，你和我在一起很安全的。",
}

local steam__jinghuangmu = fk.CreateTriggerSkill{
  name = "steam__jinghuangmu",
  events = {fk.EventPhaseStart},
  anim_type = "drawcard",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player.phase == Player.Play
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    local card = Fk:cloneCard("await_exhausted")
    card.skillName = self.name
    if player:prohibitUse(card) then return false end
    local targets = table.filter(room.alive_players, function(p)
      return not player:isProhibited(p, card)
    end)
    if #targets == 0 then return false end
    local tos = room:askForChoosePlayers(player, table.map(targets, Util.IdMapper), 1, 3, "#steam__jinghuangmu-choose", self.name, true)
    if #tos > 0 then
      room:sortPlayersByAction(tos)
      self.cost_data = {tos = tos}
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local card = Fk:cloneCard("await_exhausted")
    card.skillName = self.name
    room:useCard{
      from = player.id,
      tos = table.map(self.cost_data.tos, function(p) return {p} end),
      card = card,
    }
  end,
}
local steam__jinghuangmu_delay = fk.CreateTriggerSkill{
  name = "#steam__jinghuangmu_delay",
  mute = true,
  events = {fk.AfterCardsMove},
  can_trigger = function(self, event, target, player, data)
    if player.dead or player.chained then return false end
    local parent = player.room.logic:getCurrentEvent().parent
    if parent and parent.event == GameEvent.SkillEffect then
      parent = parent.parent
      if parent and parent.event == GameEvent.CardEffect then
        local eff = parent.data[1]
        if eff.card.name == "await_exhausted" and table.contains(eff.card.skillNames, "steam__jinghuangmu") then
          local ids = {}
          for _, move in ipairs(data) do
            if move.from == player.id and move.moveReason == fk.ReasonDiscard then
              for _, info in ipairs(move.moveInfo) do
                table.insert(ids, info.cardId)
              end
            end
          end
          if #ids == 2 and Fk:getCardById(ids[1]).color == Fk:getCardById(ids[2]).color then
            return true
          end
        end
      end
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    player:setChainState(true)
  end,
}
steam__jinghuangmu:addRelatedSkill(steam__jinghuangmu_delay)
lillia:addSkill(steam__jinghuangmu)

Fk:loadTranslationTable{
  ["steam__jinghuangmu"] = "惊惶木",
  [":steam__jinghuangmu"] = "出牌阶段开始时，你可以选择至多三名角色，视为对其使用一张【以逸待劳】，以此法弃置两张同色牌的角色横置。",
  ["#steam__jinghuangmu-choose"] = "惊惶木：你可视为对至多三名角色使用一张【以逸待劳】",
  ["#steam__jinghuangmu_delay"] = "惊惶木",
  ["$steam__jinghuangmu1"] = "喂，你，你听见我说话了吗——不是你，是你的梦。",
  ["$steam__jinghuangmu2"] = "你会不会，可能，说不定，大概，想和我一起做梦呢?",
}

local steam__liuwozhong = fk.CreateTriggerSkill{
  name = "steam__liuwozhong",
  events = {fk.HpRecover},
  anim_type = "support",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player.chained
  end,
  on_cost = function (self, event, target, player, data)
    return player.room:askForSkillInvoke(player, self.name, nil, "#steam__liuwozhong-invoke:::"..data.num)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:setChainState(false)
    local targets = table.filter(room.alive_players, function(p)
      return p ~= player and p.chained
    end)
    if #targets == 0 then return false end
    local tos = room:askForChoosePlayers(player, table.map(targets, Util.IdMapper), 1, 999,
    "#steam__liuwozhong-choose:::"..data.num, self.name, true)
    if #tos > 0 then
      room:sortPlayersByAction(tos)
      for _, pid in ipairs(tos) do
        local to = room:getPlayerById(pid)
        if not to.dead then
          to:setChainState(false)
          if not to.dead then
            room:recover { num = data.num, skillName = self.name, who = to, recoverBy = player }
          end
        end
      end
    end
  end,
}
lillia:addSkill(steam__liuwozhong)

Fk:loadTranslationTable{
  ["steam__liuwozhong"] = "流涡种",
  [":steam__liuwozhong"] = "当你回复体力后，若你横置，你可以重置包含你的任意名角色，令其余重置者也回复等量体力。",
  ["#steam__liuwozhong-invoke"] = "流涡种：你可以重置，再重置其他角色，令这些角色回复%arg点体力",
  ["#steam__liuwozhong-choose"] = "流涡种：重置其他角色，令这些角色回复%arg点体力",
  ["$steam__liuwozhong1"] = "安心睡吧，做个好梦。",
  ["$steam__liuwozhong2"] = "别看我，别看我，别看我，别看我，看我呀——",
}

local steam__yelanyao = fk.CreateActiveSkill{
  name = "steam__yelanyao",
  anim_type = "control",
  card_num = 0,
  target_num = 2,
  card_filter = Util.FalseFunc,
  prompt = "#steam__yelanyao",
  target_filter = function(self, to_select, selected)
    if #selected == 0 then return true end
    if #selected == 1 then
      local to = Fk:currentRoom():getPlayerById(to_select)
      local first = Fk:currentRoom():getPlayerById(selected[1])
      return (to.chained ~= first.chained or to.faceup ~= first.faceup) and not to:isNude()
    end
  end,
  target_tip = function (self, to_select, selected, selected_cards, card, selectable)
    if to_select == selected[1] then
      return { {content = "steam__yelanyao_get" , type = "normal"} }
    end
    if (#selected == 1 and selectable) or to_select == selected[2] then
      return { {content = "steam__yelanyao_lose", type = "warning"} }
    end
  end,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  on_use = function(self, room, effect)
    local getter = room:getPlayerById(effect.tos[1])
    local loser = room:getPlayerById(effect.tos[2])
    local cid = room:askForCardChosen(getter, loser, "he", self.name)
    room:obtainCard(getter, cid, false, fk.ReasonPrey, getter.id, self.name)
    if not loser.dead then
      loser:drawCards(1, self.name)
    end
  end,
}
lillia:addSkill(steam__yelanyao)

Fk:loadTranslationTable{
  ["steam__yelanyao"] = "夜阑谣",
  [":steam__yelanyao"] = "出牌阶段限一次，你可以选择两名武将牌状态不同的角色，令其中一名角色获得另一名角色一张牌，然后失去牌的角色摸一张牌。",
  ["steam__yelanyao_get"] = "获得牌",
  ["steam__yelanyao_lose"] = "失去牌",
  ["#steam__yelanyao"] = "夜阑谣：选择两名武将牌状态不同的角色，第一个角色获得第二个角色的一张牌，再令后者摸一张牌",
  ["$steam__yelanyao1"] = "都去睡觉吧~",
  ["$steam__yelanyao2"] = "该睡觉咯~",
}

local renata = General(extension, "steam__renata", "west", 3, 3, General.Female)

Fk:loadTranslationTable{
  ["steam__renata"] = "烈娜塔", -- 烈娜塔·戈拉斯克 Renata Glasc
  ["#steam__renata"] = "炼金男爵",
  ["illustrator:steam__renata"] = "",
  ["designer:steam__renata"] = "cyc",
  ["~steam__renata"] = "终于，我能和他们团聚了…",
}

local zhongchengjili = fk.CreateActiveSkill{
  name = "steam__zhongchengjili",
  anim_type = "drawcard",
  card_num = 0,
  target_num = 0,
  attached_skill_name = "steam__zhongchengjili&",
  card_filter = Util.FalseFunc,
  target_filter = Util.FalseFunc,
  prompt = "#steam__zhongchengjili",
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    room:loseHp(player, 1, self.name)
    if player.dead then return end
    player:drawCards(2, self.name)
    if player.dead then return end
    room:useVirtualCard("drugs", nil, player, player, self.name)
  end,
}

local zhongchengjili_other = fk.CreateActiveSkill{
  name = "steam__zhongchengjili&",
  anim_type = "drawcard",
  card_num = 0,
  target_num = 0,
  card_filter = Util.FalseFunc,
  target_filter = Util.FalseFunc,
  prompt = "#steam__zhongchengjili-other",
  target_tip = function (self, to_select, selected, selected_cards, card, selectable, extra_data)
    local to = Fk:currentRoom():getPlayerById(to_select)
    if to ~= Self and to:hasSkill(zhongchengjili) then
      return "steam__zhongchengjili_owner"
    end
  end,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0 and
    table.find(Fk:currentRoom().alive_players, function(p)
      return p ~= player and p:hasSkill(zhongchengjili)
    end)
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local targets = table.filter(room.alive_players, function(p)
      return p ~= player and p:hasSkill(zhongchengjili)
    end)
    if #targets == 0 then return end
    local owner = targets[1]
    if #targets > 1 then
      local tos = room:askForChoosePlayers(player, table.map(targets, Util.IdMapper), 1, 1, "", self.name, false)
      owner = room:getPlayerById(tos[1])
    end
    if not room:askForSkillInvoke(owner, self.name, nil, "#steam__zhongchengjili-ask:"..player.id) then return end
    owner:broadcastSkillInvoke(zhongchengjili.name)
    room:doIndicate(owner.id, {player.id})
    room:loseHp(player, 1, self.name)
    if player.dead then return end
    player:drawCards(2, self.name)
    if player.dead then return end
    room:useVirtualCard("drugs", nil, player, player, self.name)
  end,
}
Fk:addSkill(zhongchengjili_other)

renata:addSkill(zhongchengjili)

Fk:loadTranslationTable{
  ["steam__zhongchengjili"] = "忠诚激励",
  [":steam__zhongchengjili"] = "每名角色的出牌阶段限一次，其可以请求发动一次〖苦肉〗，若你同意，其视为使用一张【散】。",
  ["steam__zhongchengjili&"] = "苦肉",
  [":steam__zhongchengjili&"] = "出牌阶段限一次，你可以请求发动一次〖苦肉〗，若“忠诚激励”拥有者同意，你视为使用一张【散】。",
  ["#steam__zhongchengjili"] = "你可以〖苦肉〗，然后视为使用一张【散】",
  ["#steam__zhongchengjili-other"] = "你可以请求发动〖苦肉〗，若被同意，你视为使用【散】",
  ["#steam__zhongchengjili-ask"] = "忠诚激励：是否同意 %src 发动〖苦肉〗？",
  ["steam__zhongchengjili_owner"] = "请求对象",

  ["$steam__zhongchengjili1"] = "把水搅浑",
  ["$steam__zhongchengjili2"] = "这就叫合作",
}

local jishijiunan = fk.CreateTriggerSkill{
  name = "steam__jishijiunan",
  frequency = Skill.Limited,
  events = {fk.EnterDying},
  anim_type = "support",
  can_trigger = function(self, event, target, player, data)
    return player:usedSkillTimes(self.name, Player.HistoryGame) == 0 and player:hasSkill(self) and not target.dead
  end,
  on_cost = function (self, event, target, player, data)
    if player.room:askForSkillInvoke(player, self.name, nil, "#steam__jishijiunan-invoke:"..target.id) then
      self.cost_data = {tos = {target.id}}
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:recover({ who = target, num = target.maxHp - target.hp, recoverBy = player, skillName = self.name })
    if not target.dead then
      room:setPlayerMark(target, "@@steam__jishijiunan", 1)
    end
  end,
}

local jishijiunan_delay = fk.CreateTriggerSkill{
  name = "#steam__jishijiunan_delay",
  events = {fk.TurnEnd},
  anim_type = "negative",
  can_trigger = function(self, event, target, player, data)
    return not player.dead and player:getMark("@@steam__jishijiunan") ~= 0
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    player.room:loseHp(player, 1, jishijiunan.name)
  end,

  refresh_events = {fk.HpChanged},
  can_refresh = function (self, event, target, player, data)
    local damage = data.damageEvent
    return player:getMark("@@steam__jishijiunan") ~= 0 and data.num < 0 and damage and damage.from == player
    and target.hp <= 0 and (target.hp + data.shield_lost - data.num) > 0
  end,
  on_refresh = function (self, event, target, player, data)
    player.room:setPlayerMark(player, "@@steam__jishijiunan", 0)
  end,
}
jishijiunan:addRelatedSkill(jishijiunan_delay)
renata:addSkill(jishijiunan)

Fk:loadTranslationTable{
  ["steam__jishijiunan"] = "及时救难",
  [":steam__jishijiunan"] = "限定技，一名角色进入濒死状态时，你可以令其回复体力至上限。若如此做，每回合结束时，其失去1点体力，直到其造成致命伤害。",
  ["@@steam__jishijiunan"] = "及时救难",
  ["#steam__jishijiunan_delay"] = "及时救难",
  ["#steam__jishijiunan-invoke"] = "及时救难：你可以令 %src 回复体力至上限。但其每回合失去体力，直到造成致命伤害",
  ["$steam__jishijiunan1"] = "好好干活",
  ["$steam__jishijiunan2"] = "证明你的价值吧",
}

local eyishougou = fk.CreateActiveSkill{
  name = "steam__eyishougou",
  anim_type = "control",
  card_num = 0,
  target_num = 2,
  switch_skill_name = "steam__eyishougou",
  prompt = function (self)
    return "#steam__eyishougou-"..Self:getSwitchSkillState(self.name, false, true)
  end,
  target_tip = function (self, to_select, selected, selected_cards, card, selectable, extra_data)
    if #selected > 0 and to_select == selected[1] then
      return "steam__eyishougou_user"
    end
  end,
  card_filter = Util.FalseFunc,
  target_filter = function(self, to_select, selected, selected_cards)
    local to = Fk:currentRoom():getPlayerById(to_select)
    if #selected == 0 then
      return not to:isNude()
    elseif #selected == 1 then
      return true
    end
  end,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local user = room:getPlayerById(effect.tos[1])
    local to = room:getPlayerById(effect.tos[2])
    local isYang = player:getSwitchSkillState(self.name, true) == fk.SwitchYang
    local ids = table.filter(user:getCardIds("he"), function (id)
      local card = Fk:cloneCard("befriend_attacking")
      card.skillName = self.name
      card:addSubcard(id)
      return not user:prohibitUse(card) and not user:isProhibited(to, card)
    end)
    if #ids == 0 then return end
    if #ids > 1 then
      ids = room:askForCard(user, 1, 1, true, self.name, false, tostring(Exppattern{ id = ids }), "#steam__eyishougou-use")
    end
    local use = room:useVirtualCard("befriend_attacking", ids, user, to, self.name)
    if user.dead or not use then return end
    ids = (use.extra_data or {}).steam__eyishougou_draw or {}
    ids = table.filter(ids, function (id)
      if not table.contains(user.player_cards[Player.Hand], id) then return false end
      local c = Fk:getCardById(id)
      if isYang then
        return c.suit == Card.Spade
      else
        return c.suit ~= Card.Heart
      end
    end)
    if #ids == 0 then return end
    user:showCards(ids)
    room:addPlayerMark(user, "@steam__dunxi", #ids)
  end,
}

local eyishougou_switch = fk.CreateTriggerSkill{
  name = "#steam__eyishougou_switch",
  events = {fk.GameStart},
  mute = true,
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(eyishougou)
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local skillName = eyishougou.name
    local choices = {"steam__eyishougou_yang", "steam__eyishougou_yin"}
    local choice = room:askForChoice(player, choices, skillName, "#steam__eyishougou-switch")
    local switch_state = table.indexOf(choices, choice) - 1
    room:setPlayerMark(player, MarkEnum.SwithSkillPreName .. skillName, switch_state)
    player:setSkillUseHistory(skillName, 0, Player.HistoryGame)
  end,

  refresh_events = {fk.AfterCardsMove},
  can_refresh = function (self, event, target, player, data)
    return not player.dead
  end,
  on_refresh = function (self, event, target, player, data)
    local logic = player.room.logic
    local parent = logic:getCurrentEvent().parent
    if parent and parent.event == GameEvent.SkillEffect then
      local effect_event = parent.parent
      if effect_event and effect_event.event == GameEvent.CardEffect then
        local eff = effect_event.data[1]
        if table.contains(eff.card.skillNames, eyishougou.name) and eff.from == player.id then
          local useEvent = effect_event:findParent(GameEvent.UseCard)
          if not useEvent then return end
          local use = useEvent.data[1]
          local ids = {}
          for _, move in ipairs(data) do
            if move.toArea == Card.PlayerHand and move.to == player.id then
              for _, info in ipairs(move.moveInfo) do
                table.insertIfNeed(ids, info.cardId)
              end
            end
          end
          use.extra_data = use.extra_data or {}
          use.extra_data.steam__eyishougou_draw = use.extra_data.steam__eyishougou_draw or {}
          table.insertTableIfNeed(use.extra_data.steam__eyishougou_draw, ids)
        end
      end
    end
  end,
}
eyishougou:addRelatedSkill(eyishougou_switch)

---@param data CardUseStruct
local canTransferByDunxi = function (data, player, p)
  if player:isProhibited(p, data.card) then return false end
  -- 可以杀自己
  if data.card.trueName == "slash" then
    return true
  elseif data.card.trueName == "peach" then
    return p:isWounded()
  elseif data.card.sub_type == Card.SubtypeDelayedTrick then
    return not p:hasDelayedTrick(data.card.name) and not table.contains(p.sealedSlots, "JudgeSlot")
    -- 无距离限制
  elseif data.card.skill:modTargetFilter(p.id, {}, player, data.card, false) then
    local orig_to = data.tos[1]
    if #orig_to > 1 then
      return data.card.skill:modTargetFilter(orig_to[2], {p.id}, player, data.card, false)
    end
  end
  return true
end

local dunxi_delay = fk.CreateTriggerSkill{
  name = "#steam__eyishougou_dunxi",
  anim_type = "negative",
  events = {fk.CardUsing, fk.CardUseFinished},
  can_trigger = function(self, event, target, player, data)
    if event == fk.CardUsing then
      if player == target and player:getMark("@steam__dunxi") > 0 and
      (data.card.type == Card.TypeBasic or data.card.type == Card.TypeTrick) and #TargetGroup:getRealTargets(data.tos) == 1 then
        return not table.find(player.room.alive_players, function (p)
          return p.dying
        end)
      end
    elseif event == fk.CardUseFinished then
      return not player.dead and data.extra_data and data.extra_data.steam__dunxi_record and
        table.contains(data.extra_data.steam__dunxi_record, player.id)
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.CardUsing then
      player:broadcastSkillInvoke("steam__dunxi")
      room:removePlayerMark(player, "@steam__dunxi")
      local orig_to = data.tos[1]
      local targets = {}
      for _, p in ipairs(room.alive_players) do
        if canTransferByDunxi(data, player, p) then
          table.insert(targets, p.id)
        end
      end
      if #targets == 0 then
        data.tos = {}
        return
      end
      local random_target = table.random(targets)
      for i = 1, 3, 1 do
        for _, p in ipairs(room:getAlivePlayers()) do
          room:delay(250)
          room:setEmotion(p, "./packages/moepack/image/anim/question")
          if i == 3 and p.id == random_target then
            room:doIndicate(data.from, {random_target})
            break
          end
        end
      end
      room:sendLog{type = "#steam__dunxi_log", from = data.from, to = {random_target}, arg = data.card:toLogString(), toast = true}

      if random_target == orig_to[1] then
        data.extra_data = data.extra_data or {}
        local steam__dunxi_record = data.extra_data.steam__dunxi_record or {}
        table.insert(steam__dunxi_record, player.id)
        data.extra_data.steam__dunxi_record = steam__dunxi_record
      else
        orig_to[1] = random_target
        data.tos = { orig_to }
      end
    elseif event == fk.CardUseFinished then
      room:loseHp(player, 1, self.name)
      if player.phase == Player.Play then
        player:endPlayPhase()
      end
    end
  end,
}
eyishougou:addRelatedSkill(dunxi_delay)

renata:addSkill(eyishougou)

-- empty skill for broadcast skill audio
local dunxi = fk.CreateTriggerSkill{
  name = "steam__dunxi",
}
renata:addRelatedSkill(dunxi)

Fk:loadTranslationTable{
  ["steam__eyishougou"] = "恶意收购",
  [":steam__eyishougou"] = "转换技，游戏开始时可自选状态。出牌阶段限一次，你可以令一名角色将一张牌当【远交近攻】对你指定的另一名角色使用。然后使用者展示以此法获得的：①♠牌；②非<font color='red'>♥</font>牌；获得等量的<a href=':steam__dunxi'>“钝”标记</a>。",
  ["#steam__eyishougou-yang"] = "恶意收购：令一名角色将一张牌当【远交近攻】对你选择的角色使用，然后前者展示所有♠牌",
  ["#steam__eyishougou-yin"] = "恶意收购：令一名角色将一张牌当【远交近攻】对你选择的角色使用，然后前者展示所有非<font color='red'>♥</font>牌",
  ["steam__eyishougou_user"] = "使用者",
  ["steam__eyishougou_yang"] = "展示♠牌",
  ["steam__eyishougou_yin"] = "展示非<font color='red'>♥</font>牌",
  ["#steam__eyishougou-switch"] = "恶意收购：选择初始阴阳状态，即【远交近攻】使用者须展示的牌",
  ["#steam__eyishougou_dunxi"] = "钝袭",
  ["@steam__dunxi"] = "钝",
  ["#steam__eyishougou-use"] = "恶意收购：你须将一张牌当【远交近攻】转化使用",
  ["#steam__dunxi_log"] = "%from 使用 %arg 目标改为 %to",
  ["#steam__eyishougou_switch"] = "恶意收购",

  ["$steam__eyishougou1"] = "现在你要替我卖命了！",
  ["$steam__eyishougou2"] = "全部带走，享受痛苦！",

  ["steam__dunxi"] = "钝袭",
  [":steam__dunxi"] = "有“钝”标记的角色使用基本牌或锦囊牌时，"..
  "若目标数为1且没有处于濒死状态的角色，其移去一个“钝”，然后目标改为随机一名角色。"..
  "若随机的目标与原本目标相同，则其于此牌结算结束后失去1点体力并结束出牌阶段。",

  ["$steam__dunxi1"] = "看锤！",
  ["$steam__dunxi2"] = "且吃我一锤！",
}

local mundo = General(extension, "steam__mundo", "west", 5, 6)
Fk:loadTranslationTable{
  ["steam__mundo"] = "蒙多",
  ["#steam__mundo"] = "祖安狂人",
  ["illustrator:steam__mundo"] = "",
  ["designer:steam__mundo"] = "cyc",
  ["~steam__mundo"] = "谁来治蒙多……",
}

local steam__dalixingyi = fk.CreateActiveSkill{
  name = "steam__dalixingyi",
  anim_type = "support",
  card_num = 0,
  target_num = 1,
  prompt = "#steam__dalixingyi",
  card_filter = Util.FalseFunc,
  target_filter = function(self, to_select, selected, selected_cards)
    return #selected == 0 and Fk:currentRoom():getPlayerById(to_select):isWounded()
  end,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local to = room:getPlayerById(effect.tos[1])
    for i = 1, 5 do
      if to.dead or not to:isWounded() then break end
      local card = Fk:cloneCard("drugs")
      card.skillName = self.name
      if not room:useVirtualCard("drugs", nil, to, to, self.name) then break end
    end
  end,
}

local steam__dalixingyi_delay = fk.CreateTriggerSkill{
  name = "#steam__dalixingyi_delay",
  events = {fk.HpRecover},
  mute = true,
  can_trigger = function (self, event, target, player, data)
    return target == player and not target.dead and data.card and data.card.trueName == "drugs"
    and table.contains(data.card.skillNames, "steam__dalixingyi")
  end,
  on_cost = Util.TrueFunc,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local skillName = "steam__dalixingyi"
    local names = table.filter(U.getAllCardNames("bt"), function (name)
      local c = Fk:cloneCard(name)
      c.skillName = skillName
      return player:canUse(c, {bypass_distances = true, bypass_times = true})
      and not player:prohibitUse(c) and c.skill:getMinTargetNum() < 2
    end)
    while #names > 0 do
      local name = table.remove(names, math.random(1, #names))
      local card = Fk:cloneCard(name)
      card.skillName = skillName
      local targets = table.filter(room.alive_players, function (p)
        if player:isProhibited(p, card) then return false end
        if card.trueName == "slash" then
          return true
        elseif card.trueName == "peach" then
          return p:isWounded()
        else
          return card.skill:modTargetFilter(p.id, {}, player, card, false)
        end
      end)
      if #targets > 0 then
        local to = table.random(targets)
        room:delay(700)
        player:chat(Fk:translate("Now I ask you"))
        player:broadcastSkillInvoke("steam__dalixingyi")
        room:delay(200)
        room:useCard{from = player.id, tos = {{to.id}}, card = card, extraUse = true}
        break
      end
    end
  end,
}
steam__dalixingyi:addRelatedSkill(steam__dalixingyi_delay)

mundo:addSkill(steam__dalixingyi)

Fk:loadTranslationTable{
  ["steam__dalixingyi"] = "大力行医",
  [":steam__dalixingyi"] = "出牌阶段限一次，你可以令一名已受伤角色连续视为使用【散】直至体力回满（至多使用5张）。"..
  "其每因此回复1点体力，便发送一句“那我问你”，并视为使用一张牌名、目标随机而定的即时牌。",
  ["#steam__dalixingyi"] = "大力行医：令一名已受伤角色连续视为使用【散】直至体力回满，并随机视为使用牌！",
  ["#steam__dalixingyi_delay"] = "大力行医",
  
  ["Now I ask you"] = "那我问你",
  ["$steam__dalixingyi1"] = "别怕，我是医生。",
  ["$steam__dalixingyi2"] = "一兆万毫升的治病水儿，紧急！",
  ["$steam__dalixingyi3"] = "旧的疤痕怎么治？用新的盖过去!",
}

local udyr = General(extension, "steam__udyr", "west", 4)

Fk:loadTranslationTable{
  ["steam__udyr"] = "乌迪尔",
  ["#steam__udyr"] = "兽灵行者",
  ["illustrator:steam__udyr"] = "",
  ["designer:steam__udyr"] = "cyc",
  ["~steam__udyr"] = "终于……一片寂静……",
}

local zhonglingniudai = fk.CreateTriggerSkill{
  name = "steam__zhonglingniudai",
  events = {fk.EventPhaseStart, fk.EventPhaseEnd},
  mute = true,
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self) then
      if event == fk.EventPhaseStart then
        return player.phase == Player.Play
      else
        return player.phase == Player.Discard and
        table.find(target:getTableMark("zhengsu_skill-turn"), function (v)
          return v[2] == self.name and v[1] == player.id
        end)
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    if event == fk.EventPhaseStart then
      return player.room:askForSkillInvoke(player, self.name)
    else
      local choice
      for _, v in ipairs(target:getTableMark("zhengsu_skill-turn")) do
        if v[2] == self.name and v[1] == player.id then
          choice = v[3]
          break
        end
      end
      if not choice then return false end
      local result =  target:getMark("@" .. choice.. "-turn")
      if result == "zhengsu_failure" then
        choice = "zhengsu_failure"
        if table.contains(player:getTableMark("steam__zhonglingniudai_remove"), "steam__zhonglingniudai_fail") or
        not player.room:askForSkillInvoke(player, self.name, nil, "#steam__zhonglingniudai-iceslash") then return false end
      end
      self.cost_data = {choice = choice}
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:notifySkillInvoked(player, self.name)
    if event == fk.EventPhaseStart then
      player:broadcastSkillInvoke(self.name, math.random(2))
      U.startZhengsu(player, player, self.name, "")
    else
      local remove_list, remove = player:getTableMark("steam__zhonglingniudai_remove"), false
      local choice = self.cost_data.choice
      if choice == "zhengsu_leijin" then
        player:broadcastSkillInvoke(self.name, math.random(6, 7))
        remove = table.contains(remove_list, "steam__zhonglingniudai_lj")
      elseif choice == "zhengsu_bianzhen" then
        player:broadcastSkillInvoke(self.name, math.random(4, 5))
        remove = table.contains(remove_list, "steam__zhonglingniudai_bz")
      elseif choice == "zhengsu_mingzhi" then
        player:broadcastSkillInvoke(self.name, math.random(8, 9))
        remove = table.contains(remove_list, "steam__zhonglingniudai_mz")
      elseif choice == "zhengsu_failure" then
        player:broadcastSkillInvoke(self.name, math.random(10, 11))
        room:useVirtualCard("ice__slash", nil, player, player, self.name, true)
        if player.dead then return end
      end
      -- 执行整肃奖励
      local choices = {"draw2"}
      if player:isWounded() then
        table.insert(choices, 1, "recover")
      end
      local reward = player.room:askForChoice(player, choices, self.name, "#steam__zhonglingniudai-reward", false, {"draw2", "recover"})
      U.rewardZhengsu(player, player, reward, self.name)
      if player.dead or remove then return end
      -- 执行额外奖励
      if choice == "zhengsu_leijin" then
        U.askForUseVirtualCard(room, player, "thunder__slash", nil, self.name, nil, true, true, true, true)
      elseif choice == "zhengsu_bianzhen" then
        local targets = table.filter(room:getOtherPlayers(player, false), function (p) return not p:isAllNude() end)
        if #targets == 0 then return false end
        local tos = room:askForChoosePlayers(player, table.map(targets, Util.IdMapper),
        1, 1, "#steam__zhonglingniudai-throw", self.name, true)
        if #tos > 0 then
          local to = room:getPlayerById(tos[1])
          local cards = room:askForCardsChosen(player, to, 1, 2, "hej", self.name)
          room:throwCard(cards, self.name, to, player)
        end
      elseif choice == "zhengsu_mingzhi" then
        local tos = room:askForChoosePlayers(player, table.map(room.alive_players, Util.IdMapper),
        1, 1, "#steam__zhonglingniudai-reset", self.name, true)
        if #tos > 0 then
          local to = room:getPlayerById(tos[1])
          to:reset()
          if to.dead then return end
          tos = room:askForChooseToMoveCardInBoard(to, "#steam__zhonglingniudai-move", self.name, true)
          if #tos > 0 then
            room:askForMoveCardInBoard(to, room:getPlayerById(tos[1]), room:getPlayerById(tos[2]), self.name)
          end
        end
      end
    end
  end,

  on_lose = function (self, player)
    player.room:setPlayerMark(player, "steam__zhonglingniudai_remove", 0)
  end,
}

udyr:addSkill(zhonglingniudai)

Fk:loadTranslationTable{
  ["steam__zhonglingniudai"] = "众灵纽带",
  [":steam__zhonglingniudai"] = "出牌阶段开始时，你可以“<a href='zhengsu_desc'>整肃</a>”。"..
  "<br>☆若你“擂进”成功，你可以视为使用一张无视距离的雷【杀】。"..
  "<br>☆若你“变阵”成功，你可以弃置一名其他角色区域内至多两张牌。"..
  "<br>☆若你“鸣止”成功，你可以复原一名角色，其移动场上一张牌。"..
  "<br>☆若你整肃失败，你可以视为对自己使用一张冰【杀】，仍获得整肃奖励。",
  
  ["#steam__zhonglingniudai-reward"] = "众灵纽带：请选择整肃奖励！",
  ["#steam__zhonglingniudai-iceslash"] = "众灵纽带：你可以视为对自己使用一张冰【杀】，获得整肃奖励",
  ["#steam__zhonglingniudai-throw"] = "众灵纽带：你可以弃置一名其他角色区域内至多两张牌",
  ["#steam__zhonglingniudai-reset"] = "众灵纽带：复原一名角色，并令其移动场上一张牌",
  ["#steam__zhonglingniudai-move"] = "众灵纽带：请选择两名角色，移动其场上的牌",
  
  ["$steam__zhonglingniudai1"] = "众灵之力！", -- 开始整肃1
  ["$steam__zhonglingniudai2"] = "喜悦和力量，都在我体内涌动！", -- 开始整肃2
  ["$steam__zhonglingniudai3"] = "叉出去！罚其二十军杖！", -- 整肃失败
  ["$steam__zhonglingniudai4"] = "烈火冲锋！", -- 变阵1
  ["$steam__zhonglingniudai5"] = "山羊之灵！", -- 变阵2
  ["$steam__zhonglingniudai6"] = "赐我力量！", -- 擂进1
  ["$steam__zhonglingniudai7"] = "巨熊之灵！", -- 擂进2
  ["$steam__zhonglingniudai8"] = "赐我强身！", -- 鸣止1
  ["$steam__zhonglingniudai9"] = "野猪之灵！", -- 鸣止2
  ["$steam__zhonglingniudai10"] = "凤凰之灵！", -- 冰杀1
  ["$steam__zhonglingniudai11"] = "赐我寒风！", -- 冰杀2
}

local xianzuzhaohuan = fk.CreateActiveSkill{
  name = "steam__xianzuzhaohuan",
  anim_type = "support",
  frequency = Skill.Limited,
  card_num = 0,
  target_num = 1,
  prompt = "#steam__xianzuzhaohuan",
  interaction = function ()
    local all_choices = {"steam__zhonglingniudai_bz_info", "steam__zhonglingniudai_lj_info", "steam__zhonglingniudai_mz_info",
    "steam__zhonglingniudai_fail_info"}
    local choices = table.filter(all_choices, function(name) return not table.contains(Self:getTableMark("steam__zhonglingniudai_remove"), name) end)
    return UI.ComboBox { choices = choices, all_choices = all_choices }
  end,
  card_filter = Util.FalseFunc,
  target_filter = function(self, to_select, selected)
    return #selected == 0 and Self.id ~= to_select and self.interaction.data ~= nil
  end,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryGame) == 0
    and player:hasSkill(zhonglingniudai, true)
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local to = room:getPlayerById(effect.tos[1])
    local choice = self.interaction.data
    if choice == nil then return end
    choice = choice:sub(1, -6)
    room:addTableMark(player, "steam__zhonglingniudai_remove", choice)
    room:changeMaxHp(player, -1)
    room:handleAddLoseSkills(to, choice)
  end,
}
udyr:addSkill(xianzuzhaohuan)

Fk:loadTranslationTable{
  ["steam__xianzuzhaohuan"] = "先祖召唤",
  [":steam__xianzuzhaohuan"] = "限定技，出牌阶段，你可以减1点体力上限，删去〖众灵纽带〗中带有☆的一句，令一名其他角色获得一个仅有首句与该句的〖众灵纽带〗。",
  ["#steam__xianzuzhaohuan"] = "先祖召唤：减1点体力上限，删去〖众灵纽带〗中带有☆的一句，令一名其他角色获得之",
  ["steam__zhonglingniudai_bz_info"] = "☆若你“变阵”成功，你可以弃置一名其他角色区域内至多两张牌",
  ["steam__zhonglingniudai_lj_info"] = "☆若你“擂进”成功，你可以视为使用一张无视距离的雷【杀】",
  ["steam__zhonglingniudai_mz_info"] = "☆若你“鸣止”成功，你可以复原一名角色，其移动场上一张牌",
  ["steam__zhonglingniudai_fail_info"] = "☆若你整肃失败，你可以视为对自己使用一张冰【杀】，仍获得整肃奖励",
  
  ["$steam__xianzuzhaohuan1"] = "纷争哺育了弗雷尔卓德！",
  ["$steam__xianzuzhaohuan2"] = "巨龙之灵出窍以后，依然还会长久燃烧！",
}

local zhonglingniudai_bz = fk.CreateTriggerSkill{
  name = "steam__zhonglingniudai_bz",
  events = {fk.EventPhaseStart, fk.EventPhaseEnd},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self) then
      if event == fk.EventPhaseStart then
        return player.phase == Player.Play
      else
        return player.phase == Player.Discard and U.checkZhengsu(player, player, self.name)
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    if event == fk.EventPhaseStart then
      return player.room:askForSkillInvoke(player, self.name)
    else
      local choice
      for _, v in ipairs(target:getTableMark("zhengsu_skill-turn")) do
        if v[2] == self.name and v[1] == player.id then
          choice = v[3]
          break
        end
      end
      self.cost_data = {choice = choice}
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.EventPhaseStart then
      player:broadcastSkillInvoke(zhonglingniudai.name, math.random(2))
      U.startZhengsu(player, player, self.name, "")
    else
      local choice = self.cost_data.choice
      player:broadcastSkillInvoke(zhonglingniudai.name, math.random(4,5))
      local choices = {"draw2"}
      if player:isWounded() then table.insert(choices, 1, "recover") end
      local reward = player.room:askForChoice(player, choices, self.name, "#steam__zhonglingniudai-reward", false, {"draw2", "recover"})
      U.rewardZhengsu(player, player, reward, self.name)
      if player.dead then return end
      if choice == "zhengsu_bianzhen" then
        local targets = table.filter(room:getOtherPlayers(player, false), function (p) return not p:isAllNude() end)
        if #targets == 0 then return false end
        local tos = room:askForChoosePlayers(player, table.map(targets, Util.IdMapper),
        1, 1, "#steam__zhonglingniudai-throw", self.name, true)
        if #tos > 0 then
          local to = room:getPlayerById(tos[1])
          local cards = room:askForCardsChosen(player, to, 1, 2, "hej", self.name)
          room:throwCard(cards, self.name, to, player)
        end
      end
    end
  end,
}
Fk:addSkill(zhonglingniudai_bz)

Fk:loadTranslationTable{
  ["steam__zhonglingniudai_bz"] = "众灵纽带",
  [":steam__zhonglingniudai_bz"] = "出牌阶段开始时，你可以“<a href='zhengsu_desc'>整肃</a>”。"..
  "<br>☆若你“变阵”成功，你可以弃置一名其他角色区域内至多两张牌。",
}

local zhonglingniudai_lj = fk.CreateTriggerSkill{
  name = "steam__zhonglingniudai_lj",
  events = {fk.EventPhaseStart, fk.EventPhaseEnd},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self) then
      if event == fk.EventPhaseStart then
        return player.phase == Player.Play
      else
        return player.phase == Player.Discard and U.checkZhengsu(player, player, self.name)
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    if event == fk.EventPhaseStart then
      return player.room:askForSkillInvoke(player, self.name)
    else
      local choice
      for _, v in ipairs(target:getTableMark("zhengsu_skill-turn")) do
        if v[2] == self.name and v[1] == player.id then
          choice = v[3]
          break
        end
      end
      self.cost_data = {choice = choice}
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.EventPhaseStart then
      player:broadcastSkillInvoke(zhonglingniudai.name, math.random(2))
      U.startZhengsu(player, player, self.name, "")
    else
      local choice = self.cost_data.choice
      player:broadcastSkillInvoke(zhonglingniudai.name, math.random(6, 7))
      local choices = {"draw2"}
      if player:isWounded() then table.insert(choices, 1, "recover") end
      local reward = player.room:askForChoice(player, choices, self.name, "#steam__zhonglingniudai-reward", false, {"draw2", "recover"})
      U.rewardZhengsu(player, player, reward, self.name)
      if player.dead then return end
      if choice == "zhengsu_leijin" then
        U.askForUseVirtualCard(room, player, "thunder__slash", nil, self.name, nil, true, true, true, true)
      end
    end
  end,
}
Fk:addSkill(zhonglingniudai_lj)

Fk:loadTranslationTable{
  ["steam__zhonglingniudai_lj"] = "众灵纽带",
  [":steam__zhonglingniudai_lj"] = "出牌阶段开始时，你可以“<a href='zhengsu_desc'>整肃</a>”。"..
  "<br>☆若你“擂进”成功，你可以视为使用一张无视距离的雷【杀】。",
}


local zhonglingniudai_mz = fk.CreateTriggerSkill{
  name = "steam__zhonglingniudai_mz",
  events = {fk.EventPhaseStart, fk.EventPhaseEnd},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self) then
      if event == fk.EventPhaseStart then
        return player.phase == Player.Play
      else
        return player.phase == Player.Discard and U.checkZhengsu(player, player, self.name)
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    if event == fk.EventPhaseStart then
      return player.room:askForSkillInvoke(player, self.name)
    else
      local choice
      for _, v in ipairs(target:getTableMark("zhengsu_skill-turn")) do
        if v[2] == self.name and v[1] == player.id then
          choice = v[3]
          break
        end
      end
      self.cost_data = {choice = choice}
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.EventPhaseStart then
      player:broadcastSkillInvoke(zhonglingniudai.name, math.random(2))
      U.startZhengsu(player, player, self.name, "")
    else
      local choice = self.cost_data.choice
      player:broadcastSkillInvoke(zhonglingniudai.name, math.random(8, 9))
      local choices = {"draw2"}
      if player:isWounded() then table.insert(choices, 1, "recover") end
      local reward = player.room:askForChoice(player, choices, self.name, "#steam__zhonglingniudai-reward", false, {"draw2", "recover"})
      U.rewardZhengsu(player, player, reward, self.name)
      if player.dead then return end
      if choice == "zhengsu_mingzhi" then
        local tos = room:askForChoosePlayers(player, table.map(room.alive_players, Util.IdMapper),
        1, 1, "#steam__zhonglingniudai-reset", self.name, true)
        if #tos > 0 then
          local to = room:getPlayerById(tos[1])
          to:reset()
          if to.dead then return end
          tos = room:askForChooseToMoveCardInBoard(to, "#steam__zhonglingniudai-move", self.name, true)
          if #tos > 0 then
            room:askForMoveCardInBoard(to, room:getPlayerById(tos[1]), room:getPlayerById(tos[2]), self.name)
          end
        end
      end
    end
  end,
}
Fk:addSkill(zhonglingniudai_mz)

Fk:loadTranslationTable{
  ["steam__zhonglingniudai_mz"] = "众灵纽带",
  [":steam__zhonglingniudai_mz"] = "出牌阶段开始时，你可以“<a href='zhengsu_desc'>整肃</a>”。"..
  "<br>☆若你“鸣止”成功，你可以复原一名角色，其移动场上一张牌。",
}

local zhonglingniudai_fail = fk.CreateTriggerSkill{
  name = "steam__zhonglingniudai_fail",
  events = {fk.EventPhaseStart, fk.EventPhaseEnd},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self) then
      if event == fk.EventPhaseStart then
        return player.phase == Player.Play
      else
        return player.phase == Player.Discard and
        table.find(target:getTableMark("zhengsu_skill-turn"), function (v)
          return v[2] == self.name and v[1] == player.id
        end)
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    if event == fk.EventPhaseStart then
      return player.room:askForSkillInvoke(player, self.name)
    else
      local choice
      for _, v in ipairs(target:getTableMark("zhengsu_skill-turn")) do
        if v[2] == self.name and v[1] == player.id then
          choice = v[3]
          break
        end
      end
      if not choice then return false end
      local result =  target:getMark("@" .. choice.. "-turn")
      if result == "zhengsu_failure" then
        choice = "zhengsu_failure"
        if not player.room:askForSkillInvoke(player, self.name, nil, "#steam__zhonglingniudai-iceslash") then return false end
      end
      self.cost_data = {choice = choice}
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.EventPhaseStart then
      player:broadcastSkillInvoke(zhonglingniudai.name, math.random(2))
      U.startZhengsu(player, player, self.name, "")
    else
      local choice = self.cost_data.choice
      player:broadcastSkillInvoke(zhonglingniudai.name, math.random(10, 11))
      if choice == "zhengsu_failure" then
        room:useVirtualCard("ice__slash", nil, player, player, self.name, true)
        if player.dead then return end
      end
      local choices = {"draw2"}
      if player:isWounded() then table.insert(choices, 1, "recover") end
      local reward = player.room:askForChoice(player, choices, self.name, "#steam__zhonglingniudai-reward", false, {"draw2", "recover"})
      U.rewardZhengsu(player, player, reward, self.name)
    end
  end,
}
Fk:addSkill(zhonglingniudai_fail)

Fk:loadTranslationTable{
  ["steam__zhonglingniudai_fail"] = "众灵纽带",
  [":steam__zhonglingniudai_fail"] = "出牌阶段开始时，你可以“<a href='zhengsu_desc'>整肃</a>”。"..
  "<br>☆若你整肃失败，你可以视为对自己使用一张冰【杀】，仍获得整肃奖励。",
}

local talon = General(extension, "steam__talon", "west", 3)
talon.shield = 1
Fk:loadTranslationTable{
  ["steam__talon"] = "泰隆",
  ["#steam__talon"] = "刀锋之影",
  ["illustrator:steam__talon"] = "",
  ["designer:steam__talon"] = "cyc",
  ["~steam__talon"] = "哈哈哈哈哈哈……",
}

local daofengzhimo = fk.CreateTriggerSkill{
  name = "steam__daofengzhimo",
  events = {"fk.GeneralAppeared"},
  anim_type = "drawcard",
  can_trigger = function (self, event, target, player, data)
    return target == player and player:hasShownSkill(self)
  end,
  on_cost = Util.TrueFunc,
  on_use = function (self, event, target, player, data)
    player.room:setPlayerMark(player, "@@steam__daofengzhimo-turn", 1)
  end,
}
daofengzhimo.isHiddenSkill = true
daofengzhimo.CenterArea = true
local daofengzhimo_delay = fk.CreateTriggerSkill{
  name = "#steam__daofengzhimo_delay",
  events = {fk.TurnEnd},
  anim_type = "drawcard",
  can_trigger = function (self, event, target, player, data)
    return player:getMark("@@steam__daofengzhimo-turn") > 0
  end,
  on_cost = Util.TrueFunc,
  on_use = function (self, event, target, player, data)
    local room = player.room
    player:broadcastSkillInvoke("steam__daofengzhimo")
    local cards = table.filter(room:getBanner("@$CenterArea") or {}, function (id)
      return Fk:getCardById(id).is_damage_card
    end)
    if #cards > 0 then
      room:obtainCard(player, cards, true, fk.ReasonJustMove, player.id, "steam__daofengzhimo")
    end
  end,
}
daofengzhimo:addRelatedSkill(daofengzhimo_delay)
talon:addSkill(daofengzhimo)

Fk:loadTranslationTable{
  ["steam__daofengzhimo"] = "刀锋之末",
  [":steam__daofengzhimo"] = "隐匿技，你登场的回合结束时，你获得中央区内的伤害牌。",
  ["#steam__daofengzhimo_delay"] = "刀锋之末",
  ["@@steam__daofengzhimo-turn"] = "刀锋之末",
  
  ["$steam__daofengzhimo1"] = "速战速决吧！",
  ["$steam__daofengzhimo2"] = "他们活不长了。",
}

local zhancaochugen = fk.CreateTriggerSkill{
  name = "steam__zhancaochugen",
  events = {fk.EventPhaseStart},
  anim_type = "drawcard",
  frequency = Skill.Compulsory,
  can_trigger = function (self, event, target, player, data)
    return target == player and player:hasSkill(self) and player.phase == Player.Finish
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local ids, max_dist = {}, 0
    for _, p in ipairs(room.alive_players) do
      if player:inMyAttackRange(p) then
        max_dist = math.max(max_dist, player:distanceTo(p))
      end
    end
    if max_dist == 0 then return end
    local targets = table.map(table.filter(room.alive_players, function (p)
      return player:inMyAttackRange(p) and player:distanceTo(p) == max_dist
    end), Util.IdMapper)
    if #targets == 0 then return end
    player.room.logic:getEventsOfScope(GameEvent.UseCard, 1, function(e)
      local use = e.data[1]
      if table.find(TargetGroup:getRealTargets(use.tos), function (pid)
        return table.contains(targets, pid)
      end) then
        table.insertTableIfNeed(ids, Card:getIdList(use.card))
      end
    end, Player.HistoryTurn)
    ids = table.filter(ids, function (id) return room:getCardArea(id) == Card.DiscardPile end)
    if #ids > 0 then
      local cid = room:askForCardChosen(player, player, { card_data = { { self.name, ids } } }, self.name, "#steam__zhancaochugen-get")
      room:obtainCard(player, cid, true, fk.ReasonJustMove, player.id, self.name)
    end
  end,
}
talon:addSkill(zhancaochugen)

Fk:loadTranslationTable{
  ["steam__zhancaochugen"] = "斩草除根",
  [":steam__zhancaochugen"] = "锁定技，结束阶段，你获得本回合对攻击范围内距离最远的角色使用过的一张牌。",
  ["#steam__zhancaochugen-get"] = "斩草除根：选择一张牌获得！",
  
  ["$steam__zhancaochugen1"] = "这把刀是我的最爱…",
  ["$steam__zhancaochugen2"] = "游走于刀尖之上。",
}

local cikezhidao = fk.CreateActiveSkill{
  name = "steam__cikezhidao",
  anim_type = "control",
  card_num = 1,
  target_num = 1,
  prompt = "#steam__cikezhidao",
  card_filter = function(self, to_select, selected)
    local suit = Fk:getCardById(to_select):getSuitString(true)
    return #selected == 0 and not table.contains(Self:getTableMark("@steam__cikezhidao-phase"), suit)
    and suit ~= "log_nosuit"
  end,
  target_filter = function(self, to_select, selected, selected_cards)
    local to = Fk:currentRoom():getPlayerById(to_select)
    return #selected == 0 and (Self:getNextAlive() == to or to:getNextAlive() == Self) and not to:isRemoved()
  end,
  can_use = function(self, player)
    return #player:getTableMark("@steam__cikezhidao-phase") < 4
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local to = room:getPlayerById(effect.tos[1])
    local suit = Fk:getCardById(effect.cards[1]):getSuitString(true)
    room:addTableMark(player, "@steam__cikezhidao-phase", suit)
    room:recastCard(effect.cards, player, self.name)
    if to.dead then return end
    DIY.removePlayer(to, "-turn")
  end,
}
talon:addSkill(cikezhidao)

Fk:loadTranslationTable{
  ["steam__cikezhidao"] = "刺客之道",
  [":steam__cikezhidao"] = "出牌阶段每种花色限一次，你可以重铸一张牌，移出一名邻家直到回合结束。",
  ["#steam__cikezhidao"] = "刺客之道：重铸一张牌，移出一名邻家直到回合结束",
  ["@steam__cikezhidao-phase"] = "刺道",
  
  ["$steam__cikezhidao1"] = "又是一具阴沟里的尸体。",
  ["$steam__cikezhidao2"] = "无处可藏！",
}

local anyingtuxi = fk.CreateActiveSkill{
  name = "steam__anyingtuxi",
  anim_type = "big",
  min_card_num = 1,
  target_num = 1,
  prompt = "#steam__anyingtuxi",
  can_use = function(self, player)
    return player:getMark("@@rfenghou_readying:::"..self.name) == 0
  end,
  card_filter = function (self, to_select, selected)
    return Fk:getCardById(to_select).is_damage_card
  end,
  target_filter = function(self, to_select, selected, selected_cards)
    return #selected == 0 and to_select ~= Self.id and #selected_cards > 0
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local to = room:getPlayerById(effect.tos[1])
    local ids = table.simpleClone(effect.cards)
    player:showCards(ids)
    while not to.dead and not to:isNude() and #ids > 0 do
      local suits = {}
      for _, id in ipairs(ids) do
        table.insertIfNeed(suits, Fk:getCardById(id):getSuitString())
      end
      local discard = room:askForDiscard(to, 1, 1, true, self.name, true, ".|.|"..table.concat(suits, ","), "steam__anyingtuxi-discard", true)
      if #discard == 0 then break end
      local suit = Fk:getCardById(discard[1]).suit
      room:throwCard(discard, self.name, to, to)
      local same = table.filter(ids, function (id)
        return table.contains(player:getCardIds("h"), id) and Fk:getCardById(id).suit == suit
      end)
      if #same > 0 then
        local cid = room:askForCardChosen(to, player, { card_data = { { "discard", same } } }, self.name)
        room:throwCard(cid, self.name, player, to)
      end
      ids = table.filter(ids, function (id) return table.contains(player:getCardIds("h"), id) end)
    end
    while not to.dead and #ids > 0 do
      local card = Fk:getCardById(table.remove(ids, 1))
      if not player:prohibitUse(card) and not player:isProhibited(to, card) then
        room:useCard{from = player.id, tos = {{to.id}}, card = card, extraUse = true}
      end
      ids = table.filter(ids, function (id) return table.contains(player:getCardIds("h"), id) end)
    end
  end,
}
anyingtuxi.RfenghouReadySkill = true

talon:addSkill(anyingtuxi)

Fk:loadTranslationTable{
  ["steam__anyingtuxi"] = "暗影突袭",
  [":steam__anyingtuxi"] = "<a href='rfenghou_ready_skill'>蓄势技</a>，出牌阶段，你可以展示任意张伤害牌，令一名其他角色可以重复执行：弃置一张牌并弃置一张被展示的同花色牌。最后，你依次对其使用剩余的展示牌。",
  ["@@rfenghou_readying:::steam__anyingtuxi"] = "暗影突袭 蓄势中",
  ["#steam__anyingtuxi-discard"] = "暗影突袭：你可以弃置一张牌，并弃置一张同花色的展示牌",
  ["#steam__anyingtuxi"] = "暗影突袭：展示任意张伤害牌，对一名其他角色使用，其可以弃置同花色牌弃置你展示牌",


  ["$steam__anyingtuxi1"] = "刀下生，刀下死！",
  ["$steam__anyingtuxi2"] = "没有机会了！",
}

local viktor = General(extension, "steam__viktor", "west", 3)
viktor.shield = 1
Fk:loadTranslationTable{
  ["steam__viktor"] = "维克托",
  ["#steam__viktor"] = "奥术先驱",
  ["illustrator:steam__viktor"] = "",
  ["designer:steam__viktor"] = "cyc",
  ["~steam__viktor"] = "没有进化……就没有自由……",
}

local xianlu = fk.CreateTriggerSkill{
  name = "steam__xianlu",
  events = {fk.EventPhaseStart},
  anim_type = "support",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and not target.dead and target.phase == Player.Start
  end,
  on_cost = function(self, event, target, player, data)
    if player.room:askForSkillInvoke(target, self.name, nil, "#steam__xianlu-ask:"..player.id) then
      self.cost_data = {tos = {target.id}}
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:damage { from = player, to = target, damage = 1, skillName = self.name }
    if not player.dead then
      player:drawCards(1, self.name)
    end
    if not target.dead and target ~= player and not player:isNude() then
      local cards = room:askForCard(player, 1, 1, true, self.name, false, nil, "#steam__xianlu-give:"..target.id)
      room:obtainCard(target, cards, false, fk.ReasonGive, player.id, self.name)
    end
    if not player.dead then
      room:addPlayerMark(player, "@steam__xianlu", 1)
    end
  end,

  on_lose = function (self, player)
    player.room:setPlayerMark(player, "@steam__xianlu", 0)
  end,
}

local xianlu_attack = fk.CreateAttackRangeSkill{
  name = "#steam__xianlu_attackrange",
  correct_func = function (self, player, to)
    if player:hasSkill(xianlu) then
      return -1 + player:getMark("@steam__xianlu")
    end
  end,
}
xianlu:addRelatedSkill(xianlu_attack)
viktor:addSkill(xianlu)

Fk:loadTranslationTable{
  ["steam__xianlu"] = "先路",
  [":steam__xianlu"] = "你的攻击范围-1。一名角色的准备阶段，其可以受到你造成的1点伤害，若如此做，你摸一张牌并交给其一张牌，然后你攻击范围+1。",
  ["#steam__xianlu-ask"] = "先路：你可以受到%src造成1点伤害，然后其摸1牌并给你1牌",
  ["@steam__xianlu"] = "先路",
  ["#steam__xianlu-give"] = "先路：请交给 %src 一张牌",

  ["$steam__xianlu1"] = "我，是一切的开端！",
  ["$steam__xianlu2"] = "众生皆苦，但我会载着那些苦难的人传致于进化的荣光。",
}

local rongsheng = fk.CreateTriggerSkill{
  name = "steam__rongsheng",
  events = {fk.Damaged, fk.DamageInflicted},
  anim_type = "support",
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(self) then return false end
    if event == fk.Damaged then
      return target == player
    else
      return target ~= player and target:hasSkill(self, true) and player:getMark("steam__rongsheng-turn") == 0
    end
  end,
  on_trigger = function(self, event, target, player, data)
    if event == fk.DamageInflicted then
      return self:doCost(event, target, player, data)
    end
    self.cancel_cost = false
    for i = 1, data.damage do
      if i > 1 and(self.cancel_cost or not player:hasSkill(self)) then break end
      self:doCost(event, target, player, data)
    end
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    if event == fk.Damaged then
      local targets = table.filter(room.alive_players, function (p) return p:hasSkill(self, true) end)
      local tos = room:askForChoosePlayers(player, table.map(targets, Util.IdMapper),
      1, 1, "#steam__rongsheng-draw", self.name, true)
      if #tos > 0 then
        self.cost_data = {tos = tos}
        return true
      end
      self.cancel_cost = true
    else
      if room:askForSkillInvoke(player, self.name, nil, "#steam__rongsheng-ask:"..target.id.."::"..data.damage) then
        self.cost_data = {tos = {target.id}}
        return true
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.Damaged then
      local to = room:getPlayerById(self.cost_data.tos[1])
      to:drawCards(1, self.name)
    else
      room:setPlayerMark(player, "steam__rongsheng-turn", 1)
      room:damage { from = data.from, to = player, damage = data.damage, skillName = self.name }
      return true
    end
  end,
}
viktor:addSkill(rongsheng)

Fk:loadTranslationTable{
  ["steam__rongsheng"] = "荣生",
  [":steam__rongsheng"] = "当你受到1点伤害后，可以令一名拥有〖荣生〗的角色摸一张牌。每回合限一次，其他拥有〖荣生〗的角色受到伤害时，你可以防止之并受到同来源的等量普通伤害。",
  ["#steam__rongsheng-draw"] = "荣生：可以令一名拥有〖荣生〗的角色摸一张牌",
  ["#steam__rongsheng-ask"] = "荣生：你可以代替 %src 受到 %arg 点伤害！",

  ["$steam__rongsheng1"] = "海克斯核心是人类通往荣光的桥梁。",
  ["$steam__rongsheng2"] = "海克斯核心包容万象——包括你的力量。",
}

local guangrongjinhua = fk.CreateActiveSkill{
  name = "steam__guangrongjinhua",
  anim_type = "support",
  card_num = 0,
  min_target_num = 1,
  frequency = Skill.Limited,
  prompt = "#steam__guangrongjinhua",
  card_filter = Util.FalseFunc,
  target_filter = function(self, to_select, selected)
    local to = Fk:currentRoom():getPlayerById(to_select)
    return Self:inMyAttackRange(to) and table.contains(Self:getTableMark("steam__guangrongjinhua_record"), to.id)
  end,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryGame) == 0
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    room:sortPlayersByAction(effect.tos)
    for _, pid in ipairs(effect.tos) do
      local to = room:getPlayerById(pid)
      to:drawCards(1, self.name)
      if not to.dead then
        room:recover { num = 1, skillName = self.name, who = to, recoverBy = player }
      end
      if not to.dead then
        local skills = table.map(table.filter(to.player_skills, function (s)
          return s:isPlayerSkill(to) and s.visible
        end), Util.NameMapper)
        if #skills > 0 then
          local skill = room:askForChoices(to, skills, 0, 1, self.name, "#steam__guangrongjinhua-choice", true)[1]
          if skill then
            room:handleAddLoseSkills(to, "-"..skill.."|steam__rongsheng")
          end
        end
      end
    end
  end,
}

local guangrongjinhua_trigger = fk.CreateTriggerSkill {
  name = "#steam__guangrongjinhua_trigger",

  refresh_events = {fk.Damage},
  can_refresh = function (self, event, target, player, data)
    return target == player and player:hasSkill(guangrongjinhua, true)
  end,
  on_refresh = function (self, event, target, player, data)
    local room = player.room
    room:addTableMarkIfNeed(player, "steam__guangrongjinhua_record", data.to.id)
  end,
}
guangrongjinhua:addRelatedSkill(guangrongjinhua_trigger)

viktor:addSkill(guangrongjinhua)

Fk:loadTranslationTable{
  ["steam__guangrongjinhua"] = "光荣进化",
  [":steam__guangrongjinhua"] = "限定技，出牌阶段，你可以令攻击范围内任意名受到过你伤害的角色各摸一张牌、回复1点体力，且可选择一个技能替换为〖荣生〗。",
  ["#steam__guangrongjinhua"] = "光荣进化：令攻击范围内受到过你伤害的角色摸1牌、回1血、进化！",
  ["#steam__guangrongjinhua-choice"] = "光荣进化：你可以选择你一个技能替换为〖荣生〗",

  ["$steam__guangrongjinhua1"] = "与海克斯的明光化为一体！",
  ["$steam__guangrongjinhua2"] = "进化，如骤雨狂风！",
}

local orianna = General(extension, "steam__orianna", "west", 3)
local concerto_of_the_loom = fk.CreateTriggerSkill{
  name = "steam__concerto_of_the_loom",
  anim_type = "special",
  frequency = Skill.Compulsory,
  events = {fk.RoundStart},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) and player.room:getCardArea(player:getMark(self.name)) ~= Card.PlayerEquip then
      local card = Fk:getCardById(player:getMark(self.name))
      return player:canUseTo(card, player)
    end
  end,
  on_use = function (self, event, target, player, data)
    local card = Fk:getCardById(player:getMark(self.name))
    player.room:useCard{
      from = player.id,
      tos = {{player.id}},
      card = card,
    }
  end,

  refresh_events = {fk.BeforeCardsMove},
  can_refresh = function(self, event, target, player, data)
    return player:hasSkill(self, true)
  end,
  on_refresh = function(self, event, target, player, data)
    local cancel_move = {}
    for _, move in ipairs(data) do
      if move.from and move.proposer and move.proposer ~= player.id and move.skillName ~= "role__wooden_ox_skill" then
        local move_info = {}
        for _, info in ipairs(move.moveInfo) do
          if info.cardId == player:getMark(self.name) and info.fromArea == Card.PlayerEquip then
            if not player.room:getPlayerById(move.from).dead then
              table.insert(cancel_move, info.cardId)
            end
          else
            table.insert(move_info, info)
          end
        end
        move.moveInfo = move_info
      end
    end
  end,

  on_acquire = function (self, player, is_start)
    local room = player.room
    local id = room:printCard("role__wooden_ox", Card.Diamond, 5).id
    room:setPlayerMark(player, self.name, id)
  end,
}
local concerto_of_the_loom_trigger = fk.CreateTriggerSkill{
  name = "#steam__concerto_of_the_loom_trigger",
  anim_type = "special",
  frequency = Skill.Compulsory,
  events = {fk.EventPhaseStart, fk.SkillEffect},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(concerto_of_the_loom) then
      if event == fk.EventPhaseStart then
        return target == player and player.phase == Player.Start
      elseif event == fk.SkillEffect then
        return data.name == "role__wooden_ox_skill" and
          table.contains(target:getCardIds("e"), player:getMark("steam__concerto_of_the_loom"))
      end
    end
  end,
  on_use = function (self, event, target, player, data)
    U.skillCharged(player, 1)
  end,
}
local order_defense = fk.CreateTriggerSkill{
  name = "steam__order_defense",
  events = {fk.Damaged},
  anim_type = "support",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and player:getMark("skill_charge") > 0 and not target.dead and
      table.find(player.room.alive_players, function (p)
        return target:distanceTo(p) <= player:getMark("skill_charge") and
          table.contains(p:getCardIds("e"), player:getMark("steam__concerto_of_the_loom"))
      end)
  end,
  on_cost = function(self, event, target, player, data)
    local choices = {}
    for i = 1, math.min(player:getMark("skill_charge"), 2), 1 do
      table.insert(choices, tostring(i))
    end
    table.insert(choices, "Cancel")
    local choice = player.room:askForChoice(player, choices, self.name, "#steam__order_defense-invoke::"..target.id)
    if choice ~= "Cancel" then
      self.cost_data = {tos = {target.id}, choice = tonumber(choice)}
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local n = self.cost_data.choice
    U.skillCharged(player, -n)
    target:drawCards(n, self.name)
  end,

  on_acquire = function (self, player, is_start)
    U.skillCharged(player, 2, 3)
  end,
  on_lose = function (self, player, is_death)
    U.skillCharged(player, -2, -3)
  end,
}
local order_shock_wave = fk.CreateActiveSkill{
  name = "steam__order_shock_wave",
  anim_type = "control",
  card_num = 0,
  target_num = 1,
  prompt = "#steam__order_shock_wave",
  can_use = function(self, player)
    return player:getMark("skill_charge") > 0
  end,
  interaction = UI.ComboBox {choices = {
    "steam__order_shock_wave1",
    "steam__order_shock_wave2",
  }},
  card_filter = Util.FalseFunc,
  target_filter = function(self, to_select, selected)
    if #selected == 0 then
      local p = table.find(Fk:currentRoom().alive_players, function (p)
        return table.contains(p:getCardIds("e"), Self:getMark("steam__concerto_of_the_loom"))
      end)
      if p == nil then return end
      local target = Fk:currentRoom():getPlayerById(to_select)
      if self.interaction.data == "steam__order_shock_wave1" then
        if target:getNextAlive(true) == p or p:getNextAlive(true) == target then
          return p:canMoveCardInBoardTo(target, Self:getMark("steam__concerto_of_the_loom"))
        end
      elseif self.interaction.data == "steam__order_shock_wave2" then
        if #p:getPile("$role_carriage&") > 4 then return end
        return not target:isNude() and p:distanceTo(target) <= 1
      end
    end
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    U.skillCharged(player, -1)
    local target = room:getPlayerById(effect.tos[1])
    if self.interaction.data == "steam__order_shock_wave1" then
      room:moveCardIntoEquip(target, player:getMark("steam__concerto_of_the_loom"), self.name, false, player.id)
    elseif self.interaction.data == "steam__order_shock_wave2" then
      local p = table.find(room.alive_players, function (p)
        return table.contains(p:getCardIds("e"), player:getMark("steam__concerto_of_the_loom"))
      end)
      if p == nil then return end
      local card = room:askForCard(target, 1, 1, true, self.name, false, nil, "#steam__order_shock_wave-ask::"..p.id)
      p:addToPile("$role_carriage&", card, false, self.name)
    end
  end,
}
concerto_of_the_loom:addRelatedSkill(concerto_of_the_loom_trigger)
orianna:addSkill(concerto_of_the_loom)
orianna:addSkill(order_defense)
orianna:addSkill(order_shock_wave)
Fk:loadTranslationTable{
  ["steam__orianna"] = "奥莉安娜",
  ["#steam__orianna"] = "发条魔灵",
  ["illustrator:steam__orianna"] = "Alex Flores",
  ["designer:steam__orianna"] = "cyc",

  ["steam__concerto_of_the_loom"] = "发条协奏",
  [":steam__concerto_of_the_loom"] = "锁定技，轮次开始时，若场上没有【魔偶】（【木牛流马】），你使用一张。【魔偶】被其他角色以发动装备技能"..
  "以外的方式移动时，取消之。准备阶段，或【魔偶】的装备技能被发动后，你的蓄力点+1。",
  ["steam__order_defense"] = "指令:防卫",
  [":steam__order_defense"] = "蓄力技（2/3），与【魔偶】距离X以内的一名角色受到伤害后，你可以消耗至多2蓄力点，令其摸等量张牌（X为蓄力点数）。",
  ["steam__order_shock_wave"] = "指令:冲击波",
  [":steam__order_shock_wave"] = "蓄力技（2/3），出牌阶段，你可以消耗1蓄力点执行以下一项：1.将【魔偶】移动一个座次；2.令【魔偶】距离1以内的"..
  "一名角色将一张牌置入之中。",
  ["#steam__concerto_of_the_loom_trigger"] = "发条协奏",
  ["#steam__order_defense-invoke"] = "指令:防卫：你可以消耗至多2蓄力点，令 %dest 摸牌",
  ["#steam__order_shock_wave"] = "指令:冲击波：消耗1蓄力点执行一项",
  ["steam__order_shock_wave1"] = "将【魔偶】移动一个座次",
  ["steam__order_shock_wave2"] = "令一名角色将一张牌置入【魔偶】",
  ["#steam__order_shock_wave-ask"] = "指令:冲击波：请将一张牌置入 %dest 的【魔偶】",

  ["$steam__concerto_of_the_loom1"] = "我有很犀利的魔偶——",
  ["$steam__concerto_of_the_loom2"] = "我们是一体的——",
  ["$steam__order_defense1"] = "保护——",
  ["$steam__order_defense2"] = "防卫——",
  ["$steam__order_shock_wave1"] = "破坏——",
  ["$steam__order_shock_wave2"] = "掠夺——",
  ["~steam__orianna"] = "（机械音）",
}

local sett = General(extension, "steam__sett", "west", 4, 5)
local haymaker = fk.CreateTriggerSkill{
  name = "steam__haymaker",
  anim_type = "defensive",
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player.phase == Player.Finish
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askForSkillInvoke(player, self.name, nil, "#steam__haymaker-invoke")
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:changeMaxHp(player, -1)
    if not player.dead then
      room:changeShield(player, 1)
    end
  end,
}
local haymaker_trigger = fk.CreateTriggerSkill{
  name = "#steam__haymaker_trigger",
  anim_type = "drawcard",
  events = {fk.HpChanged},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(haymaker) and data.reason == "damage" and data.shield_lost > 0
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local cards = table.filter(room.draw_pile, function (id)
      return Fk:getCardById(id).is_damage_card
    end)
    if #cards == 0 then return end
    cards = table.random(cards, data.shield_lost)
    room:moveCardTo(cards, Card.PlayerHand, player, fk.ReasonDraw, "steam__haymaker", nil, false, player.id, "@@steam__haymaker-inhand")
  end,

  refresh_events = {fk.PreCardUse},
  can_refresh = function (self, event, target, player, data)
    return target == player and data.card:getMark("@@steam__haymaker-inhand") > 0
  end,
  on_refresh = function (self, event, target, player, data)
    data.extraUse = true
  end,
}
local haymaker_targetmod = fk.CreateTargetModSkill{
  name = "#steam__haymaker_targetmod",
  bypass_times = function(self, player, skill, scope, card, to)
    return card and card:getMark("@@steam__haymaker-inhand") > 0
  end,
}
local show_stopper = fk.CreateTriggerSkill{
  name = "steam__show_stopper",
  anim_type = "control",
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player.phase == Player.Start and
      #player:getAvailableEquipSlots(Card.SubtypeWeapon) > 0 and
      player.room:getCardArea(player:getMark(self.name)) == Card.Void
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local success, dat = room:askForUseActiveSkill(player, "steam__show_stopper_active",
      "#steam__show_stopper-invoke", true, nil, false)
    if success and dat then
      self.cost_data = {tos = dat.targets}
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:loseHp(player, 1, self.name)
    if player.dead then return end
    local to, choices = nil, {}
    if #self.cost_data.tos > 0 then
      to = room:getPlayerById(self.cost_data.tos[1])
      if not table.contains({"blank_shibing", "blank_nvshibing", "hiddenone"}, to.general) then
        table.insert(choices, to.general)
      end
      if not table.contains({"", "blank_shibing", "blank_nvshibing", "hiddenone"}, to.deputyGeneral) then
        table.insertIfNeed(choices, to.deputyGeneral)
      end
    else
      choices = table.random(room.general_pile, 3)
    end
    local choice = ""
    if #choices == 1 then
      choice = choices[1]
    else
      choice = room:askForGeneral(player, choices, 1, true)
    end
    room:setPlayerMark(player, "@steam__show_stopper-turn", { choice, Fk.generals[choice].maxHp })

    if #self.cost_data.tos == 0 then
      table.removeOne(room.general_pile, choice)
      room.logic:getCurrentEvent():findParent(GameEvent.Turn, true):addCleaner(function()
        table.insertIfNeed(room.general_pile, choice)
      end)
    elseif to then
      local gender = Fk.generals[choice].gender
      if to.general == choice then
        room.logic:getCurrentEvent():findParent(GameEvent.Turn, true):addCleaner(function()
          room:changeHero(to, choice, false, false, false, false, true)
        end)
        room:changeHero(to, gender == General.Male and "blank_shibing" or "blank_nvshibing", false, false, false, false, true)
      elseif to.deputyGeneral == choice then
        room.logic:getCurrentEvent():findParent(GameEvent.Turn, true):addCleaner(function()
          room:changeHero(to, choice, false, true, false, false, false)
        end)
        room:changeHero(to, gender == General.Male and "blank_shibing" or "blank_nvshibing", false, true, false, false, false)
      end
    end

    local skillList = {}
    for _, skillName in ipairs(Fk.generals[choice]:getSkillNameList()) do
      local skill = Fk.skills[skillName]
      if string.sub(Fk:getDescription(skillName, "zh_CN"), 7, 12) ~= "技，" and not skill.isHiddenSkill then
        table.insert(skillList, skillName)
      end
    end
    if #skillList > 0 then
      room:setPlayerMark(player, "steam__show_stopper_skills-turn", skillList)
    end
    local card = Fk:getCardById(player:getMark(self.name))
    room:setCardMark(card, MarkEnum.DestructOutMyEquip, 1)
    room:moveCardIntoEquip(player, card.id, self.name, true)
  end,

  refresh_events = {fk.AfterCardsMove},
  can_refresh = function(self, event, target, player, data)
    for _, move in ipairs(data) do
      if move.from == player.id then
        for _, info in ipairs(move.moveInfo) do
          if info.fromArea == Card.PlayerEquip and info.cardId == player:getMark(self.name) then
            return true
          end
        end
      end
    end
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    room:setPlayerMark(player, "steam__show_stopper_skills-turn", 0)
    room:setPlayerMark(player, "@steam__show_stopper-turn", 0)
  end,

  on_acquire = function (self, player, is_start)
    local room = player.room
    local leftArm = room:printCard("steam__goddianwei_left_arm").id
    room:setPlayerMark(player, self.name, leftArm)
  end,
}
local show_stopper_delay = fk.CreateTriggerSkill{
  name = "#steam__show_stopper_delay",
  mute = true,
  events = {fk.TurnEnd},
  can_trigger = function(self, event, target, player, data)
    return target == player and table.contains(player:getCardIds("e"), player:getMark("steam__show_stopper"))
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    player.room:moveCardTo(player:getMark("steam__show_stopper"), Card.Void, nil, fk.ReasonJustMove)
  end,
}
local show_stopper_active = fk.CreateActiveSkill{
  name = "steam__show_stopper_active",
  card_num = 0,
  min_target_num = 0,
  max_target_num = 1,
  card_filter = Util.FalseFunc,
  target_filter = function(self, to_select, selected, selected_cards)
    if #selected == 0 and to_select ~= Self.id then
      local target = Fk:currentRoom():getPlayerById(to_select)
      return not table.contains({"blank_shibing", "blank_nvshibing", "hiddenone"}, target.general) or
        not table.contains({"", "blank_shibing", "blank_nvshibing", "hiddenone"}, target.deputyGeneral)
    end
  end,
}
haymaker:addRelatedSkill(haymaker_trigger)
haymaker:addRelatedSkill(haymaker_targetmod)
Fk:addSkill(show_stopper_active)
show_stopper:addRelatedSkill(show_stopper_delay)
sett:addSkill(haymaker)
sett:addSkill(show_stopper)
Fk:loadTranslationTable{
  ["steam__sett"] = "瑟提",
  ["#steam__sett"] = "腕豪",
  ["illustrator:steam__sett"] = "Alex Flores",
  ["designer:steam__sett"] = "cyc",

  ["steam__haymaker"] = "蓄意轰拳",
  [":steam__haymaker"] = "结束阶段，你可以减1点体力上限，获得1点护甲。你失去1点护甲后，摸一张伤害牌，令之不计次数。",
  ["steam__show_stopper"] = "叹为观止",
  [":steam__show_stopper"] = "准备阶段，你可以失去1点体力，然后选择一名其他角色的武将牌或从武将牌堆中发现一张武将牌，将之置入你的武器栏"..
  "（无花色点数，攻击范围为其体力上限，武器技能为其武将牌上的无标签技；替换原装备），本回合结束时复位其武将牌。",
  ["#steam__haymaker-invoke"] = "蓄意轰拳：是否减1点体力上限，获得1点护甲？",
  ["#steam__haymaker_trigger"] = "蓄意轰拳",
  ["@@steam__haymaker-inhand"] = "蓄意轰拳",
  ["steam__show_stopper_active"] = "叹为观止",
  ["#steam__show_stopper-invoke"] = "叹为观止：失去1点体力，选择一名角色的武将牌，或不选角色发现一张武将牌，将之置入你的武器栏，回合结束复位",
  ["@steam__show_stopper-turn"] = "",
  ["#steam__show_stopper_delay"] = "叹为观止",

  ["$steam__haymaker1"] = "准备好，要见血了。",
  ["$steam__haymaker2"] = "想给大哥来一拳？那你可千万别打偏了。",
  ["$steam__show_stopper1"] = "终结技来啦！",
  ["$steam__show_stopper2"] = "给我——砸！",
  ["$steam__show_stopper3"] = "起飞咯！",
  ["$steam__show_stopper4"] = "会很疼的！",
  ["~steam__sett"] = "我要求……重赛……",
}

local leftArm = fk.CreateWeapon{
  name = "&steam__goddianwei_left_arm",
  suit = Card.NoSuit,
  number = 0,
  attack_range = 1,
  dynamic_attack_range = function(self, player)
    if player then
      local mark = player:getTableMark("@steam__show_stopper-turn")
      return #mark == 2 and tonumber(mark[2]) or nil
    end
  end,
  dynamic_equip_skills = function(self, player)
    if player then
      return table.map(player:getTableMark("steam__show_stopper_skills-turn"), Util.Name2SkillMapper)
    end
  end,
}
Fk:loadTranslationTable{
  ["steam__goddianwei_left_arm"] = "左膀",
  ["goddianwei_left_arm"] = "左膀",
  [":steam__goddianwei_left_arm"] = "这是神典韦的左膀，蕴含着【杀】之力。",
}
leftArm.package = extension
Fk:addCard(leftArm)

local nasus = General(extension, "steam__nasus", "west", 4)
local siphoning_strike = fk.CreateTriggerSkill{
  name = "steam__siphoning_strike",
  anim_type = "offensive",
  events = {fk.CardUsing},
  times = function(self)
    return Self:getMark(self.name)
  end,
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and data.card.trueName == "slash" and
      player:usedSkillTimes(self.name, Player.HistoryTurn) == 0
  end,
  on_cost = function (self, event, target, player, data)
    return player.room:askForSkillInvoke(player, self.name, nil, "#steam__siphoning_strike-invoke")
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local new_card = Fk:cloneCard("hanqing__enemy_at_the_gates", data.card.suit, data.card.number)
    local c = table.simpleClone(data.card)
    for k, v in pairs(c) do
      if new_card[k] == nil then
        new_card[k] = v
      end
    end
    if data.card:isVirtual() then
      new_card.subcards = data.card.subcards
    else
      new_card.id = data.card.id
    end
    new_card.skillNames = data.card.skillNames
    new_card.skill = Fk.skills["hanqing__enemy_at_the_gates_skill"]
    data.card = new_card
    data.disresponsiveList = table.map(room.players, Util.IdMapper)
    local n = #room.logic:getEventsOfScope(GameEvent.UseCard, 999, function(e)
      local use = e.data[1]
      return use.from == player.id and use.card.number == 12
    end, Player.HistoryGame)
    if n > 0 then
      data.extra_data = data.extra_data or {}
      data.extra_data.num = (data.extra_data.num or 0) + n
    end
  end,

  refresh_events = {fk.AfterCardUseDeclared},
  can_refresh = function (self, event, target, player, data)
    return target == player and player:hasSkill(self, true) and data.card.number == 12
  end,
  on_refresh = function (self, event, target, player, data)
    player:broadcastSkillInvoke(self.name, 3)
    player.room:addPlayerMark(player, self.name, 1)
  end,

  on_acquire = function (self, player, is_start)
    local n = #player.room.logic:getEventsOfScope(GameEvent.UseCard, 999, function(e)
      local use = e.data[1]
      return use.from == player.id and use.card.number == 12
    end, Player.HistoryGame)
    player.room:setPlayerMark(player, self.name, n)
  end,
}
local spirit_fire = fk.CreateActiveSkill{
  name = "steam__spirit_fire",
  anim_type = "control",
  min_card_num = 1,
  target_num = 0,
  prompt =  "#steam__spirit_fire",
  can_use = function (self, player, card, extra_data)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) < 2
  end,
  card_filter = function(self, to_select, selected)
    if #selected == 0 then
      return true
    else
      return Fk:getCardById(to_select):compareSuitWith(Fk:getCardById(selected[1]))
    end
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local suit = Fk:getCardById(effect.cards[1]):getSuitString(true)
    room:recastCard(effect.cards, player, self.name)
    if not player.dead then
      room:addTableMark(player, "@steam__spirit_fire-turn", suit)
    end
  end,
}
local spirit_fire_invalidity = fk.CreateInvaliditySkill {
  name = "#steam__spirit_fire_invalidity",
  invalidity_func = function(self, from, skill)
    if skill.attached_equip then
      local c = table.find(from:getCardIds("e"), function (id)
        return Fk:getCardById(id).name == skill.attached_equip
      end)
      return c and table.find(Fk:currentRoom().alive_players, function (p)
        return table.contains(p:getTableMark("@steam__spirit_fire-turn"), Fk:getCardById(c):getSuitString(true))
      end)
    end
  end
}
local wither = fk.CreateTriggerSkill{
  name = "steam__wither",
  anim_type = "control",
  events = {fk.Damage, fk.Damaged},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self) then
      local turn_event = player.room.logic:getCurrentEvent():findParent(GameEvent.Turn)
      if turn_event == nil then return end
      local to = turn_event.data[1]
      if not to.dead and to:getAttackRange() > 0 then
        self.cost_data = {tos = {to.id}}
        return true
      end
    end
  end,
  on_cost = function (self, event, target, player, data)
    if player.room:askForSkillInvoke(player, self.name, nil, "#steam__wither-invoke::"..self.cost_data.tos[1]) then
      return true
    else
      self.cost_data = nil
    end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(self.cost_data.tos[1])
    room:addPlayerMark(to, "steam__wither-turn", 1)
    player:drawCards(1, self.name)
  end,
}
local wither_attackrange = fk.CreateAttackRangeSkill{
  name = "#steam__wither_attackrange",
  correct_func = function (self, from, to)
    return - from:getMark("steam__wither-turn")
  end,
}
spirit_fire:addRelatedSkill(spirit_fire_invalidity)
wither:addRelatedSkill(wither_attackrange)
nasus:addSkill(siphoning_strike)
nasus:addSkill(spirit_fire)
nasus:addSkill(wither)
Fk:loadTranslationTable{
  ["steam__nasus"] = "内瑟斯",
  ["#steam__nasus"] = "沙漠死神",
  ["illustrator:steam__nasus"] = "Christian Fell",
  ["designer:steam__nasus"] = "cyc",

  ["steam__siphoning_strike"] = "汲魂痛击",
  [":steam__siphoning_strike"] = "每回合限一次，你使用【杀】时，可以令之改为按【兵临城下】结算，且亮出牌数+X（X为你本局使用Q点牌的张数）。",
  ["steam__spirit_fire"] = "灵魂烈焰",
  [":steam__spirit_fire"] = "出牌阶段限两次，你可以重铸任意张同花色牌，令本回合场上该花色的牌失效。",
  ["steam__wither"] = "枯萎",
  [":steam__wither"] = "你造成或受到伤害后，若当前回合角色攻击范围大于0，你可以摸一张牌令之-1直到本回合结束。",
  ["#steam__siphoning_strike-invoke"] = "汲魂痛击：是否将此【杀】改为【兵临城下】？",
  ["#steam__spirit_fire"] = "灵魂烈焰：重铸任意张同花色牌，本回合场上此花色牌失效",
  ["@steam__spirit_fire-turn"] = "灵魂烈焰",
  ["#steam__wither-invoke"] = "枯萎：是否摸一张牌，令 %dest 本回合攻击范围-1？",
}






return extension
